Forums

[resolved] page and category array question (10 posts)

  1. noski2009
    Member
    Posted 11 months ago #

    Does anyone know how get the following code to also apply to a category post as well?

    <div id="header-logo" onclick="location.href='<?php bloginfo('url'); ?>'" style="cursor: pointer;" >
    <?php if (is_page(array('1', '2', '3','4', '5', '6', '7', '7'))) $logo_image = 'subLogo.jpg';
    else $logo_image = 'mainLogo.jpg';?>
    <img src="<?php bloginfo('stylesheet_directory'); ?>/images/<?php echo $logo_image;?>" alt="<?php bloginfo('name'); ?>" />
    </div>

    Thanks

  2. Peter vanDoorn
    Member
    Posted 11 months ago #

    Personally, I wouldn't do it like that - there's a far simpler way of doing it using CSS. But, only if your theme adds semantic classes to your <body>.

    Using these semantic classes you can change the style of objects depending on which page you're viewing. Your logo could then be displayed using a background image rather than an IMG tag.

    For example, in your header.php file your would have:

    <div id="logo"></div>

    In your CSS you would then have:

    #logo {background: url(mainLogo.jpg);} /* for all other pages */
    .pageid-1 #logo, pageid-2 #logo, pageid-3 #logo, catid-23 #logo {background: url(subLogo.jpg);} /* for the pages you want to change */

    These CSS classes might be different in your theme, so just have a look at the pages in your browser and look at the source to see what they should be.

    Hope that helps

    Peter

  3. noski2009
    Member
    Posted 11 months ago #

    Thanks for your post Peter,

    I see what your saying, I'm using Twenty Ten as a child theme and I think it use's it's own (crazy) semantic classes to the body tag i.e.

    <body class="single single-post postid-393 single-format-standard logged-in admin-bar">

    I suppose there's a way I could get it to stop doing that and add my own classes, I might look in to that too.

  4. Peter vanDoorn
    Member
    Posted 11 months ago #

    Yeah, so you've got the postid-393, which is the unique identifier for that particular post. How about if you're viewing a category post? It might have something like catid-5 or something (I tend not to use categories to differentiate my posts, so I can't be sure!)

    If you want to see the principle in action, have a look at this site of mine: planetearthinstituteworldwide.org - I use this method to change the background image of the whole page depending on the section you're viewing as well as the heading colours to match (click your way through the menus top menus to see).

    Have fun!

    Peter

  5. alchymyth
    The Sweeper
    Posted 11 months ago #

    http://codex.wordpress.org/Conditional_Tags

    check either
    in_category() (for single posts)
    or
    is_category() (for category archive pages)

  6. noski2009
    Member
    Posted 11 months ago #

    Thanks alchymyth, and Peter,

    Had a look the wordpress codex, bit above my level of understanding when trying to combine my code with that. Think I'm going to try and add a second header and add
    include(STYLESHEETPATH."/header2.php");?>
    to the relevant categories.

  7. Peter vanDoorn
    Member
    Posted 11 months ago #

    There is a simpler way as the get_header() function accepts a name, which will call in an alternative header file.

    eg - get_header() loads the standard header.php but get_header('home') will load header-home.php

  8. noski2009
    Member
    Posted 11 months ago #

    Thanks petervandoorn, I tried the get_header('header2') thing but it just didn't seem to work at all, the include(STYLES-yada, yada, yada bit works ok though, just need to change one css element for the logo and it's done.

  9. Peter vanDoorn
    Member
    Posted 11 months ago #

    Did you get the name of the header .php file right? get_header('header2') would look for a file called header-header2.php!

  10. noski2009
    Member
    Posted 11 months ago #

    Yea sorry should have put down get_header( $header2 ); ?>

Reply

You must log in to post.

About this Topic