2

I have two custom post types: event and contact:

http://acicafoc.josoroma.com/contactenos

http://acicafoc.josoroma.com/eventos

Both of them uses a custom taxonomy: country

I just created a template named: taxonomy-country.php

But I Need two separated templates, one for events who uses countries and another one for contacts who uses countries. For example, to display all events in United States or all contacts from Costa Rica.

This is my actual code of taxnomy-country.php, but only for events who uses countries.

<?php
/**
 * The template for displaying Countries Taxonomy.
 *
 */

get_header();


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


//print_r($term);


$args = array();

$args['post_type']  = 'event';
$args['taxonomy']   = $term->taxonomy;
$args['term']   = $term->slug;


query_posts($args); 

?>
        <div id="container">
            <div id="content" role="main">

                <h1 class="page-title"><?php
                    printf( __( 'Archives: %s', 'twentyten' ), '<span>' . $term->name . '</span>' );
                ?></h1>
                <?php
                    $category_description = category_description();
                    if ( ! empty( $category_description ) )
                        echo '<div class="archive-meta">' . $category_description . '</div>';

                /* Run the loop for the category page to output the posts.
                 * If you want to overload this in a child theme then include a file
                 * called loop-category.php and that will be used instead.
                 */
                get_template_part( 'loop', 'category' );
                ?>

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

<?php get_sidebar(); ?>
<?php get_footer(); ?>

Thanks in advance.

2 Answers 2

3

You use get_query_var('post_type') to set the post type in your args array

$args['post_type']  = get_query_var('post_type');

and also include the right loop part based on that for example:

if (get_query_var('post_type') == "event"){
   get_template_part( 'loop', 'event' );
}else{
   get_template_part( 'loop', 'other' );
}
1

Have you already look into what comes back from $term-taxonomy?

Try this right before your query:

echo '<pre>';
print_r($term-taxonomy);
echo '</pre>';

I don't know exactly the output without trying it now, but i guess it's an array and in this case you could just take the taxonomy you need.

Note: You don't need to specify $args = array(). The conversion to an array already happens when you type $args[] = '';

1
  • completely missunderstood you. i thought two taxonomies, not post types.
    – kaiser
    Commented Mar 10, 2011 at 19:23

Your Answer

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

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