Show Only Category (Not Subcategory) Content

If you ever wanted to only show the content of the category you were on in the category view of WordPress (instead of the category you are on plus all of it's subcategories - you can easily do so by adding the code below to the template that is used to show your category content

You would start your loop with this:

PHP:
<?php $cat = intval( get_query_var('cat') ); while (have_posts()) : the_post(); if (in_category($cat) ) : ?>

Put your title, content functions here

and where you normally see the

PHP:
<?php endwhile;?>

call, put

PHP:
<?php endif;endwhile; ?>

to close the additional (in_category) if statement.

This code gets the current category and then only displays categories that are in that category (not sub category)

Comments/Pingbacks/Trackbacks

Add a Comment or trackback from your own site.

5 Responses

  1. Larry

    i tried your code!

    and it doesn’t work!

  2. jzelazny

    Send over your code so I can see it and help you.

  3. Unfarttoof

    Thank you

  4. Amanda Gillespie

    Thankyouthankyouthankyou! This totally works and was EXACTLY what I needed! Thanks so much.

  5. jzelazny

    I am glad I could help!

Leave a Reply