WordPress.org

Forums

Category name and description won't display (3 posts)

  1. chazVnG
    Member
    Posted 3 years ago #

    I'm having trouble getting the category name and description to show up in my theme. The page is here: http://shoptrs.vineandgrain.com/category/accessories

    I want it to show up for the category page and any single pages, so I thought I could do it with is_single and the code I found on wordpress's support site, but I'm obviously doing something wrong. It's outside the loop, but I don't think that makes a difference.

    I'm trying to use the following code:

    <div id="header-text-top">
    	<?php if (is_single('')) { ?>
          <h1 class="pagetitle"><?php echo single_cat_title(); ?></h2>
          <h3> <?php echo category_description(); ?> </h3>
    	<?php  } ?>
    </div> <!-- header-text-top -->

    Any ideas that could help me? Thanks in advance

  2. alchymyth
    Forum Moderator
    Posted 3 years ago #

    I want it to show up for the category page and any single pages

    the code is_single() stops the code from showing in the category archive pages,
    while single_cat_title() does not work in single posts, only works in category archives;
    similar for category_description(), unless you use the category id with it.
    (

    for single post, try yo use get_the_category()

    be aware, that a single post can have more than one category.

    http://codex.wordpress.org/Function_Reference/single_cat_title
    http://codex.wordpress.org/Function_Reference/get_the_category
    http://codex.wordpress.org/Function_Reference/category_description

  3. chazVnG
    Member
    Posted 3 years ago #

    Wow, that was fast. Thanks.

    Cool, I didn't know about is_single and single_cat would only work on certain pages, that's a huge help. I put together an if statement to help pull the right title depending on the page you're on.

    I've got the category name to show up on both pages and category pages, but I'm still stuck getting the description to display on pages for some reason. This is what I have now:

    <div id="header-text-top">
    	<?php if (is_category()) { ?>
    	     <h1 class="pagetitle"><?php echo single_cat_title(); ?></h2>
    	     <h3><?php echo category_description(); ?></h3>
    	<?php  } else { ?>
    	  <h1><?php $category = get_the_category();
    			echo $category[0]->cat_name;
    		?></h1>
    	  <h3><?php $category = get_the_category();
    	  		echo category_description(); ?></h3>
    	<?php } ?>
    
    </div> <!-- header-text-top -->

    Here's a page where the description isn't showing up: http://shoptrs.vineandgrain.com/nylon-case-klh-84b

Topic Closed

This topic has been closed to new replies.

About this Topic