i know how to define custom post template vai plugins very easily but i want without plugins how can i define custom post template for particular category post.

say like i have one category "members" under this category have ten post. so i want when show those member post that time show custom template.

see bellow code from twentytwelve theme category.php file

            /* Start the Loop */
            while ( have_posts() ) : the_post();

                /* Include the post format-specific template for the content. If you want to
                 * this in a child theme then include a file called called content-___.php
                 * (where ___ is the post format) and that will be used instead.
                get_template_part( 'content', get_post_format() );


            twentytwelve_content_nav( 'nav-below' );

        <?php else : ?>
            <?php get_template_part( 'content', 'none' ); ?>
        <?php endif; ?> 

see in above code say get_template_part( 'content', get_post_format() ); and see get_template_part( 'content', 'none' ) now i want when "members" category post will open it will one custom page.. like content-members.php file, so i think code will be like that get_template_part( 'content', 'members' )

so how can define in category page members category post will open content-members.php file


You can use is_category to check if the category is "members" and then load the appropriate template.

In get_template_part() use the template name for the second parameter instead of get_post_format().

In this example your template should be named "content-members.php."

while ( have_posts() ) : the_post();

    if ( is_category( 'members' ) ) {

         get_template_part( 'content', 'members' );

    } else {

        get_template_part( 'content', get_post_format() );


  • thanks you so much @epilektric ... and how can i define single post too.. mean which members category post show in custome page. like single-members.php page – pagol Aug 18 '13 at 18:09
  • i already tried bellow code in single.php file but not work <?php if ( is_category( 'members' ) ) { get_template_part( 'content', 'members' ); } else { get_template_part( 'content', 'common' ); } ?> i think category not tigger here. – pagol Aug 18 '13 at 18:27
  • @pagol If my answer worked for you I'd appreciate the up vote. Thanks! – epilektric Aug 18 '13 at 20:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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