Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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...

share|improve this question
add comment

1 Answer

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

share|improve this answer
    
Wow thanks this works fine (just correct 2 formating errors but it's great) !! And I can put another parameter like post_per_page ? –  Aurélien Denis Jun 29 '11 at 10:00
    
you can put as many as you want –  Bainternet Jun 29 '11 at 10:37
    
Thanks all works fine now. First time I post a question here... so impressed by the quality ! –  Aurélien Denis Jun 29 '11 at 12:09
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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