ThemeShaper Forums » Thematic


Add Category title to single page, category page

(4 posts)
  • Started 9 years ago by wlanni
  • Latest reply from helgatheviking
  • This topic is not a support question
  1. wlanni


    I'm working on a site where content is being filtered throughout the site using categories. The site owners are going to want to use a category as a blog, but then we're also using categories to filter out "news and announcements" and "featured home page items."

    In order to make sure it's really clear where a user is, then, I needed to add the category title to the category page, and the single post page. However, I did not want it to appear in the date archive.

    By the way, I'm using WordPress' built in navigation menu, so in order to point to a category page, all I did was add the category to the menu. Bam. Done. (unfortunately this means I couldn't set up a template page for the category easily, but oh well).

    I attached this to the navigation above, as that was the only hook I could find that appeared on the pages I wanted these titles to show up on.

    Here's the code (most of which is grabbed from wordpress codex and forum):

    //put blogtitle onto a single page
    function blogtitle_on_single_page() {
    	if (!is_date()) {
    	<h1><?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> '; }
    <?php }
    Posted 9 years ago #
  2. hmmm...
    have you tried

    if (!is_archive()) {

    other than that, can't you just specify

    if (is_single() || is_category()) {

    hope this helps

    Posted 9 years ago #
  3. gillispj

    This works perfectly for, how ever I am wondering if there is a way to limit the amount of categories that show up? For example I would like for only the the first cat to show.

    Posted 7 years ago #
  4. not a thematic question, in theory you don't do a foreach and just grab the first item in the array, using array notation

    let me google that for you:

    read the first result.

    you should consider why you are putting things in multiple categories. if you need that type of categorization, you might want to consider using tags.

    Posted 7 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.