Forums

[resolved] category / child category conditional (3 posts)

  1. kjeft
    Member
    Posted 2 years ago #

    I am designing my category.php file. I would like to link to different CSS files depending on what category the post is assigned to. Basically, if a post if from category 1 or a child category of 1 I would like to link to cat1.css and if the post is from category 2 (or child category of 2) I would want to link cat2.css

    Below is my code from category-header.php Unfortunately it is not working, it doesn't display the child categories.

    <?php if ( is_category(1) ) {
    	echo '<link rel="stylesheet" href="' . get_bloginfo(template_directory) . '/style/css/cat1.css" type="text/css" media="screen" />';
    	} else {
    	echo '<link rel="stylesheet" href="' . get_bloginfo(template_directory) . '/style/css/cat2.css" type="text/css" media="screen" />'; }

    Any help is much appreciated!

  2. MichaelH
    Volunteer
    Posted 2 years ago #

    Wouldn't you use in_category instead of is_category?
    See an example: http://codex.wordpress.org/The_Loop#Style_Posts_From_Some_Category_Differently

    Related:
    Conditional Tags

  3. kjeft
    Member
    Posted 2 years ago #

    Ah yes, works perfectly! Thanks very much for your help

Topic Closed

This topic has been closed to new replies.

About this Topic