Showing current taxonomy terms

I’ve created a custom post type called “References” and a custom taxonomy “Genre”.

I have 2 terms : Applications and Games.

Read More

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…

Related posts

Leave a Reply

1 comment

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