Soporte » Plugins y Hacks » ayuda con este codigo

  • Resuelto antoniorodriguezduran

    (@antoniorodriguezduran)


    Este codigo muestra imagenes en cada una de las subcategorias de los posts, pero ahora he creado unos custom posts en concreto uno llamado seguridad…. Como puedo adaptar este codigo para mostrar las subcategorias con imagen en la taxonomia del custom post llamda seguridad.

    <?php get_header(); ?>
    <div id="content">
    
    	<!--the loop-->
    	<?php $subCategories = array() ?>
    	<?php if (have_posts()) : ?>
    
    	<h6>
    	<?php $post = $posts[0]; // Hack. Set $post so that the_date() works. ?>
    	<?php /* If this is a category archive */ if (is_category()) { ?>
    	<?php echo single_cat_title(); ?>
    	</h6>
            <?php
                foreach (get_categories() as $category) {
                    if( strpos($_SERVER['REQUEST_URI'],$category->slug)) {
                        break;
                    }
                }
                $subCategories = split('/',get_category_children($category->cat_ID));
                $subCategories = array_slice($subCategories, 1);
                ?>
            <ul id="subcategories">
                <?php foreach ($subCategories as $subCategoryId): ?>
                    <?php $subCategory = get_category($subCategoryId) ?>
                    <?php $url = get_settings('home') . '/seccion/' . $category->slug . '/' . $subCategory->slug ?>
    
                <li class="subcategories">
                    <a href="<?php echo $url ?>">
                        <img src="<?php echo get_settings('home') . '/images/subcat-' . $subCategory->slug . '.jpg' ?>"
                             title="<?php echo $subCategory->name ?>" />
                        <span><?php echo $subCategory->name ?></span>
                    </a>
                </li>
    
                <?php endforeach ?>
            </ul>
    	<?php /* If this is a daily archive */ } elseif (is_day()) { ?>
    	Archive for <?php the_time('F jS, Y'); ?>
    
    	<?php /* If this is a monthly archive */ } elseif (is_month()) { ?>
    	Archive for <?php the_time('F, Y'); ?>
    
    	<?php /* If this is a yearly archive */ } elseif (is_year()) { ?>
    	Archive for <?php the_time('Y'); ?>
    
    	<?php /* If this is a search */ } elseif (is_search()) { ?>
    	Search Results
    
    	<?php /* If this is an author archive */ } elseif (is_author()) { ?>
    	Author Archive
    
    	<?php /* If this is a paged archive */ } elseif (isset($_GET['paged']) && !empty($_GET['paged'])) { ?>
    	Blog Archives
    
    	<!--do not delete-->
    	<?php } ?>
    	</h6>
    
    	<!--loop article begin-->
    	<?php if ( $subCategories === array() ): ?>
    	<?php while (have_posts()) : the_post(); ?>
    	<!--post title as a link-->
    	<h3 id="post-<?php the_ID(); ?>"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h2>
    
    	<!--Post Meta-->
    	<div class="post-meta-top">
    	<div class="auth"><span>Creado por <strong><?php the_author_posts_link(); ?></strong></span></div>
    	<div class="date"><span><?php the_time('F j, Y'); ?></span></div>
    	<div class="clearboth"></div>
    	</div>
    
    	<!--optional excerpt or automatic excerpt of the post-->
    	<?php the_content(); ?>
    
    	<!--Post Meta-->
    	<div class="post-meta-bottom">
    	<!--<?php if (function_exists('the_tags')) { ?><strong>Tags: </strong><?php the_tags('', ', ', ''); ?><br /><?php } ?>-->
    	<div class="cat"><span class="cats"><?php the_category(', ') ?></span><span class="tags"><?php the_tags('', ', ', ''); ?></span></div>
    	<div class="clearboth"></div>
    	</div>
    
           <!--one post end-->
    	<?php endwhile; ?>
            <?php endif ?>
    
           <?php if ( $subCategories === array() ): ?>
                <!-- Previous/Next page navigation -->
                <div class="page-nav">
                        <div class="nav-previous"><?php previous_posts_link('&larr; Previous Page') ?></div>
                        <div class="nav-next"><?php next_posts_link('Next Page &rarr;') ?></div>
                </div>
           <?php endif ?>
    
    	<!-- do not delete-->
    	<?php else : ?>
    
    	Not Found
    
    	<!--do not delete-->
    	<?php endif; ?>
    
    <!--archive.php end-->
    
    </div>
    <!--include sidebar-->
    <?php get_sidebar();?>
    <!--include footer-->
    <?php get_footer(); ?>
Viendo 2 respuestas - de la 1 a la 2 (de un total de 2)
  • Jeick WpCOL

    (@jeickball)

    para crear un loop que muestre el contenido de custom types, te puedo recomendar que le hagas una personalización a la consulta (WP Query) (http://codex.wordpress.org/Class_Reference/WP_Query) de esta manera:

    $args = array(
    	'post_type' => 'seguridad',
    	'tax_query' => array(
    		array(
    			'taxonomy' => 'camaras'
    		)
    	)
    );
    $miquery = new WP_Query( $args );
    
    <?php if ( $miquery->have_posts() ): ?>
    <?php while ( $miquery->have_posts() ) : $miquery->the_post(); ?>
     <!-- tu contenido a mostrar de cada post -->
    <?php endwhile; ?>
    <?php endif; ?>
    Iniciador del debate antoniorodriguezduran

    (@antoniorodriguezduran)

    Muchas gracias.

Viendo 2 respuestas - de la 1 a la 2 (de un total de 2)
  • El debate ‘ayuda con este codigo’ está cerrado a nuevas respuestas.