Support » Fixing WordPress » Automatic post title loop in taxonomy.php

  • Many thanks to Justin Tadlock for posting the following piece of code in the post Using custom taxonomies to create a movie database:

    $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );

    It helped me in writing the following bit of code (subject to review). The code will automatically show the posts for whatever custom taxonomy term page one is on. In order to have an automatic loop in taxonomy.php it appears that one might be able to do the following:

    <?php $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); ?>              
    <?php query_posts( array($term->taxonomy => $term->name) ); ?>
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <?php the_title(); ?>
    <?php the_excerpt(); ?>
    <?php endwhile; else: ?>
    <p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
    <?php endif; ?>

    Is there anything in the code that needs to be improved?

Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Automatic post title loop in taxonomy.php’ is closed to new replies.