Need help with a code for a different logo for each category (7 posts)

  1. rulethenation
    Posted 2 years ago #


    Each category on my site has its own color scheme and I want the logo to change with respects to it.

    Right now i have something like this

    <?php if (in_category( '955' )) $logo_image = 'dopefuselogotopgreen.png';
                          else $logo_image = 'dopefuselogotop.png';?>
    <a id="omc-logo" href="<?php echo home_url();?>"><img src="http://dopefuse.com/<?php echo $logo_image;?>" alt="<?php bloginfo('name');?> logo" <?php if ($omc_logo_image === NULL) { echo('height="96"'); }?> /></a>

    But it doesnt work, anyone know what im doing wrong?

  2. Adam
    Posted 2 years ago #

    I believe that in_category expects a categroy-id to be an integer (if it is a string it will assume a categroy-slug) so loose the quotes around 955 and see if that works.

    Having said that, wouldn't it work better with just CSS? The body element has a class .category-955 So you could do something like:

    .category-955 #omc-logo {
    background: url('logo-green.png');

    .category-10 #omc-logo {
    background: url('logo-blue.png');


  3. alchymyth
    Forum Moderator
    Posted 2 years ago #

    are you aiming a single posts or at category archive pages?

    for category archive pages, try to use is_category(955) - you can also use the category name or slug; http://codex.wordpress.org/Function_Reference/is_category

    can you post a direct link to a page or post where this is not working?

    what is the result? - no image? - the wrong image? - ?

  4. rulethenation
    Posted 2 years ago #

    Im aiming for single posts and category pages, if you rollover your mouse over my menu, each category is a different color and each post under that category has that same color scheme, so im trying to make the logo match that

    i also tried taking out the quotes and it didnt work, ill have to try the CSS option when I have time,

    these are the archive page, and the a page in that category that should have a green logo, however my code so far has no worked




  5. alchymyth
    Forum Moderator
    Posted 2 years ago #

    seems to work already for single posts - example 'atman - december'
    (will only work if the post is direct in the category)

    to include the cat archives, generally this should work:

    <?php if ( is_single() && in_category( 955 ) || is_category( 955 ) ) $logo_image = 'dopefuselogotopgreen.png';
                          else $logo_image = 'dopefuselogotop.png';?>
  6. rulethenation
    Posted 2 years ago #

    Beautiful. Thank you sir.

  7. Skalibur1
    Posted 2 years ago #

    Very Good Mr Aclhymyth

    I will put the full code That I am running

    <?php if ( is_single() && in_category( 1 ) || is_category( 1 ) ) $logo_image = 'logo_cat1.png';
                          else $logo_image = 'logo_cat1.png';?>  
    <?php if ( is_single() && in_category( 6 ) || is_category( 6 ) ) $logo_image = 'logo_cat6.png';?>
    <a id="omc-logo" href="<?php echo home_url();?>"><img src="http://www.dientesblancos.com/muro/wp-content/themes/pinboard/<?php echo $logo_image;?>" alt="<?php bloginfo('name');?> logo" <?php if ($omc_logo_image === NULL) { echo('height="96"'); }?> /></a>

    Note that I removed else $logo_image = 'logo_cat1.png';?> for the cat 6 becouse the main logo of the site is logo_cat1.png in this example.

Topic Closed

This topic has been closed to new replies.

About this Topic