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 created a custom taxonomy slug is 'event_type' and created terms like social, educational and religious. I want to have template page where I can show posts related to these terms. you can say I need to access this url: http://localhost/test/event_type/social/

How I can create a template for this and for this url too http://localhost/test/event_type/

This taxonomy is related to custom post type named as 'event'

Any help regarding this

share|improve this question
add comment

2 Answers

I think that what you're looking for is in the Template Hierarchy. You should be able to use taxonomy-event_type.php to do exactly what you want with it.

share|improve this answer
    
<?php $terms = get_terms('event_type'); echo '<ul>'; foreach ($terms as $term) { echo '<li><a href="'.get_term_link($term->slug, 'event_type').'">'.$term->name.'</a></li>'; } echo '</ul>'; ?> here is my code from where i am getting the link. but that says nothing found. I created the page you suggested but no nothing found –  sajid Jan 23 '12 at 20:25
    
What template is it calling? –  m0r7if3r Jan 23 '12 at 20:32
add comment

I used a modified version of Justin Tadlock's code at his blog which allows you to create single post templates based on category (slug and id), author or tag.

My modified code is below:

/**
* Filter the single_template with our custom function
*/
add_filter('single_template', 'my_single_template');

/**
* Single template function which will choose our template
*/
 function my_single_template($single) {
    global $wp_query, $post;

    /**
    * Checks for single template by custom taxonomy 'event_types'
    * Change 'event_types' to whatever your custom taxonomy is called
    * Check by category slug and ID
    */

    //Only change 'event' post type
    if( 'event' != get_post_type($post) )
       return $single;

    //Where your single fiels are located inside your theme
    $single_template_path = get_stylesheet_directory().'/single/';

    //Get the taxonomy terms
    $cats = get_the_terms($post->ID,'event_types');
    if ( !$cats )
       return $single;

    foreach( $cats as $cat ) :

        if(file_exists($single_template_path . '/single-cat-' . $cat->slug . '.php'))
            return $single_template_path . '/single-cat-' . $cat->slug . '.php';

        elseif(file_exists($single_template_path . '/single-cat-' . $cat->term_id . '.php'))
            return $single_template_path  . '/single-cat-' . $cat->term_id . '.php';

    endforeach;
    return $single;

}

You would then add your new custom template files into /wp-content/themes/your-template-name/single, naming them accordingly.

Using this function you could create a template for a tag called featured within a custom taxonomy of event_types by creating a file called single-cat-featured.php

share|improve this answer
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.