Support » Fixing WordPress » add diferent classes depending on category

  • 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!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Michael

    (@alchymyth)

    Forum Moderator

    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!

    Michael

    (@alchymyth)

    Forum Moderator

    <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 😉

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

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘add diferent classes depending on category’ is closed to new replies.