1

I've created a custom post type called "References" and a custom taxonomy "Genre".

I have 2 terms : Applications and Games.

My problem is that I'd like to show posts associated in Applications on a page (and the same for the games). I believe WordPress do this like doing the same for tags....

In fact, I just need to make a query and getting the current term of the page.

Here is what I tried but I get the same list for each terms page (Applications and Games) :

<?php get_header(); ?>


        <div class="container" role="main">

                            <h1 class="entry-title"><?php single_cat_title(); ?></h1>
<div class="entry-content ref">
    <?php

    $loop = new WP_Query( array( 'post_type' => 'references' , 'genre' => '') ); ?>
    <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>

        <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>

                <h2 class="entry-title"><?php the_title(); ?></h2>

                <div class="ref"><?php the_content(); ?></div>

        </div><!-- #post-## -->

        <?php the_post_thumbnail();?>

    <?php endwhile; // end of the loop. ?>

</div><!-- .entry-content -->


        </div><!-- #container -->

<?php get_footer(); ?>

Hope someone can help me. I've Googled for a week now...

1 Answer 1

2

try this:

<?php get_header(); ?>
<? // get the current term
    $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );

    <div class="container" role="main">
        <h1 class="entry-title"><?php echo $term->name; ?></h1>
    <div class="entry-content ref">
    <?php

    $loop = new WP_Query( array( 'post_type' => 'references' , 'genre' => $term->slug) ); ?>
    <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>

        <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>

                <h2 class="entry-title"><?php the_title(); ?></h2>

                <div class="ref"><?php the_content(); ?></div>

        </div><!-- #post-## -->

        <?php the_post_thumbnail();?>

    <?php endwhile; // end of the loop. ?>

</div><!-- .entry-content -->


        </div><!-- #container -->

<?php get_footer(); ?>

And you should put this in your theme inside taxonomy-genre.php

3
  • Wow thanks this works fine (just correct 2 formating errors but it's great) !! And I can put another parameter like post_per_page ? Jun 29, 2011 at 10:00
  • you can put as many as you want
    – Bainternet
    Jun 29, 2011 at 10:37
  • Thanks all works fine now. First time I post a question here... so impressed by the quality ! Jun 29, 2011 at 12:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.