WordPress.org

Ready to get started?Download WordPress

Forums

Category Templates - Totally lost (6 posts)

  1. eveums
    Member
    Posted 8 years ago #

    I am using 1.5.2 and using the Relaxation theme. I would like to display a different header image based on the different category of post.

    I've reviewed all the codex pages and the support questions, but I'm still very lost. I also tried using the Categories template, but that didn't work at all. I'm really confused!

    1) Do I need to create category.php, category-1.php, etc.? I don't have any category.php pages so far. I really just want everything to look the same, except for the header image.

    2) I get the impression I need to use some sort of "if category-8, then header-8" code somewhere. But I'm not sure where this would go. Does it go in the index.php? Or header.php? Or style.css??

    Thanks for any help!

  2. Mark (podz)
    Support Maven
    Posted 8 years ago #

    It's something very close to this.
    In 'header.php', put this:

    <h1 id="header"
    class="<?php if(is_home()) echo('header1');
    elseif(is_category('beans') ) echo('header2');
    elseif(is_category('balloons') ) echo('header3');
    elseif(is_category('badgers') ) echo('header4');
    elseif(is_single()) echo('header5');
    elseif(is_page())echo('header6'); ?>">
    <a href="<?php bloginfo('url'); ?>">
    <?php bloginfo('name'); ?></a></h1>

    Then in your css:
    h1.header1 {
    background-image: url('home.jpg');
    background-repeat:no-repeat;
    height: 145px;
    }

    h1.header2 {
    background-image: url('beans.jpg');
    background-repeat:no-repeat;
    height: 145px;
    }

    You'll need to adjust a couple of bits there, but that will get you a whole lot closer.

  3. eveums
    Member
    Posted 8 years ago #

    Podz, Thanks for the tips, they were SOOO helpful. With your help, I have the header-switch working on the category archive pages.

    However, on individual posts, no header shows up at all. What I would like is to have the corresponding header show up on the single post from that category.

    I've looked at single.php page in my theme (I assume that template controls single posts...?) and it calls the header.php in the same way that archive.php does. Is there a way to get the header-switch to work on a single post display? And if so, where do I put the code?

    THANKS A MILLION FOR ANY HELP!

  4. eveums
    Member
    Posted 8 years ago #

    Also wanted to note that I tried filling in the above like:
    elseif(is_single('badgers')) echo('header5');
    ... and that didn't work either.

  5. joelwalsh
    Member
    Posted 8 years ago #

    Wow, it's like you two read my mind with this post exchange. I've been wondering about this for days.

    Does it work the same way for footer etc.?

    Do you have to call it with h1? Because it's much better to have each post's title be the h1, and not having dozens of pages with the exact same h1. I'm referring not only to users but search engines. Could you call it with a div? Is there a div in the header template?

  6. onenationunderdog
    Member
    Posted 8 years ago #

    this plugin shd do the trick. is there another way to do it?
    http://txfx.net/code/wordpress/force-category-template/

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags