WordPress.org

Ready to get started?Download WordPress

Forums

add diferent classes depending on category (5 posts)

  1. rooob
    Member
    Posted 3 years ago #

    i need to add a different class to the header depending on the page you are, right?

    So i have it like this:

    <div id="header" <?php
    			  if (is_page('home') ) { echo " class=\"pichome\"";}
    			  elseif (is_page('somos') ) { echo " class=\"picsomos\"";}
    			  elseif (is_page('hacemos') ) { echo " class=\"pichacemos\"";}
    			  elseif (is_page('informate') ) { echo " class=\"picinformate\"";}
    			  elseif (is_page('equipo') ) { echo " class=\"picequipo\"";}
    			  elseif (is_page('links') ) { echo " class=\"piclinks\"";}
    			  elseif (is_page('comunicate') ) { echo " class=\"piccomunica\"";}
    			  elseif (is_page('biblioteca') ) { echo " class=\"picbiblio\"";}
    
    			  else {echo " class=\"none\"";} ?>
    
        >

    and it works fine for pages, but how do i do it for different post categories?

    i've tried with the category ID, full URL, and nothing
    how can i do it? any ideas?

    thank a lot!

  2. alchymyth
    The Sweeper & Moderator
    Posted 3 years ago #

  3. rooob
    Member
    Posted 3 years ago #

    sorry about the delay, i tried that, but didnt work. (or at least i didnt know how to use it correctly)

    any other ideas?

    thanks!

  4. alchymyth
    The Sweeper & Moderator
    Posted 3 years ago #

    <div id="header" <?php
    			  if (is_page('home') ) { echo " class=\"pichome\"";}
    			  elseif (is_page('somos') ) { echo " class=\"picsomos\"";}
    			  elseif (is_page('hacemos') ) { echo " class=\"pichacemos\"";}
    			  elseif (is_page('informate') ) { echo " class=\"picinformate\"";}
    			  elseif (is_page('equipo') ) { echo " class=\"picequipo\"";}
    			  elseif (is_page('links') ) { echo " class=\"piclinks\"";}
    			  elseif (is_page('comunicate') ) { echo " class=\"piccomunica\"";}
    			  elseif (is_page('biblioteca') ) { echo " class=\"picbiblio\"";}
    
    elseif (is_category('cat name one') ) { echo " class=\"cat-name-one\"";}
    //above example is for category archive
    
    elseif (is_single() && in_category('post cat name') ) { echo " class=\"post-cat-name\"";}
    //above example is for a category in single post
    
    			  else {echo " class=\"none\"";} ?>
    
        >

    hope this helps ;-)

  5. rooob
    Member
    Posted 3 years ago #

    man, that worked!!!
    THANK YOU SO MUCH!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags