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:
  1. <?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:
  1. <?php endwhile;?>

call, put

PHP:
  1. <?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)

11 Responses to “Show Only Category (Not Subcategory) Content”

  1. Larry says:

    i tried your code!

    and it doesn’t work!

  2. jzelazny says:

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

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

  4. jzelazny says:

    I am glad I could help!

  5. michael says:

    Is there anyway to get this to work on the homepage?

  6. Tobi says:

    Perfect! Thank you!

  7. Steef says:

    PERFECT with triple !!!!

    it works great was looking for it for hours you made my day

  8. jzelazny says:

    Glad I could help!

  9. Thanks so much. This is EXACTLY what I needed.

  10. dave says:

    How can i implement these codes,,can you show the whole code

Leave a Reply