WordPress.org

Ready to get started?Download WordPress

Forums

Show the top category name (4 posts)

  1. borbs
    Member
    Posted 6 years ago #

    Hi!

    Is there a way to show, on my post page, ONLY the top category?
    If I have a structure like "MOVIES > DRAMA", I am able to show "DRAMA" on it. But I would like to show ONLY "MOVIES". How can I do that?

    Thank you!

  2. MichaelH
    Member
    Posted 6 years ago #

    Assuming Movies (parent Category) is Category ID 5 and Drama Category (child Category) is 16, you could create a Category Template, category-5.php to show only the posts in the Movies Category.

  3. MichaelH
    Member
    Posted 6 years ago #

    I'll amend that previous statement above, as clicking on a Category link for a parent Category does show the posts that belong to both parent and the children Categories.

    But, to a Category Template, you can add this construct inside your loop to limit the posts to a specific category:

    if ( in_category(get_query_var('cat')) ) {
    // display your post stuff here
    }
  4. borbs
    Member
    Posted 6 years ago #

    Ok, thanks MichaelH!

Topic Closed

This topic has been closed to new replies.

About this Topic