Forums

Different Text on Some Category Pages (Codex) (2 posts)

  1. dominoeffect
    Member
    Posted 3 years ago #

    Just looking at this advice for putting category-sensitive code in category.php.

    http://codex.wordpress.org/Category_Templates#Different_Text_on_Some_Category_Pages

    <?php if (is_category('Category A')) { ?>
    This is the text to describe category A
    
    <?php } elseif (is_category('Category B')) { ?>
    This is the text to describe category B

    Does anyone know if this could be used on single.php? For example, to run an advert beside all posts of a certain category?

    Thanks in advance for any input!
    `

  2. anix
    Member
    Posted 3 years ago #

    I did something similar. I looped through all of the categories and depending on the category id, I added that category name to a variable which then prints after the loop. You can do something similar.

    Here is my code:

    $theCatName = "";
    foreach((get_the_category()) as $category) {
    	if ($category->cat_ID != '36' && $category->cat_ID != 39 && $category->cat_ID != '8') {
            	$theCatName = $theCatName.", ".$category->cat_name;
    	}
    }
    echo $theCatName;

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags