Support » Themes and Templates » Show only one category title for posts with more than one

  • Hello,

    I have my site set up with different blog categories as menu items. So when a user navigates to “News” for example, I want the title of the page to say only “News” and show any posts marked as news.

    I am using this code that I found on the forums:
    <h4><?php $categories = get_the_category(); foreach($categories as $category) { $cat_name = $category->name; if($cat_name != 'featured') echo '<a href="'.get_category_link($category->term_id).'">'.$cat_name . '</a> '; } ?></h4>

    However, whenever a blog post has more than one category, the title shows all the categories picked up from the latest blog post on that page.

    For example, in the “Recent Activities” page, the latest post is attached to both News and Recent activities, so “News Recent Activities” is showing up as the title.

    In “News”, the latest post is only attached to “News” so it’s showing correctly, but when it was showing only the other post (on Typography) which is attached to both “News” and “Recent Activities”, it then showed “News Recent Activities”.

    Similarly, when you enter the individual post page, it shows all the categories attached to it. (Sample)

    My questions are:

    1) what code can I use to have only the title showing for the category page I am on? That is, if I navigate to the “News” blog category page in my main menu, only “News” shows?

    2) How can I force only the title for the category section I’m in show up for the individual blog post? That is, if I navigated to a particular story from the News section, then only News would show up. But if I clicked through that article from the Press Releases section, then Press Releases would show up as the title. Is this at all possible?


Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Show only one category title for posts with more than one’ is closed to new replies.