WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Twenty Eleven Header Image using is_category (8 posts)

  1. Pioneer Valley Web Design
    Member
    Posted 1 year ago #

    On this site, I am trying to have specific (not random) header images show per category (and once achieved properly apply to other blogs). I am able to do this per post using the featured image at 1000px x 288px and that works but I want to have maybe 10-12 header images (at 1000px x 288px) only and set that up once and be done. Any other categories will use a default header image.

    What is the best method?

  2. Digital Raindrops
    Member
    Posted 1 year ago #

    I have some evolving posts on ways to do this, each post has a working example downladable twenty eleven child theme to play with and copy any code from.

    This one just uses the header from the first post it finds in a category, but is restrictive if you are using the featured image for lists etc:

    This one you upload a header (Appearance > Headers) with the name being the category {slug}

    So category slug latest-news will use an uploaded header with the image being latest-news.jpg

    This one has a lot more features, category description using a custom post type, sort ASC or DESC, select different layouts for each category, and select a category header from a dropdown.

    HTH

    David

  3. Pioneer Valley Web Design
    Member
    Posted 1 year ago #

    @David, do you do this on any site and which method do you use? What site(s)? Please make sure it is: Twenty Eleven Header Image using is_category ...

  4. Digital Raindrops
    Member
    Posted 1 year ago #

    @SwansonPhotos,

    @David, do you do this on any site and which method do you use? What site(s)?

    My website is meant as a learning tool, I only write posts and create child themes when I think something might be of use to a few others.

    I do not get to use much of the code myself as I do not create themes for others, most posts and themes are created after reading posts on this forum.

    Please make sure it is: Twenty Eleven Header Image using is_category ...

    Most of the posts on my website have a download, the downloads on all three linked posts are twenty eleven child themes, and the files include category.php, header.php, functions.php, where the changes are called.

    The idea is that you have a fully working child theme example to test and all the code you need to merge with your own theme.

    Polite Observation:
    Looking at your website you have your themes folder as 'wp-content/themes/twentyeleven/', if you have modified any files then you may lose the changes.

    Later this week there is a scheduled new WordPress release with a new twenty eleven theme, if you update the twenty eleven theme, your themes folder files will be replaced.

    HTH

    David

  5. Pioneer Valley Web Design
    Member
    Posted 1 year ago #

    Thanks for clarifying, now does anyone have a working example?

  6. Pioneer Valley Web Design
    Member
    Posted 1 year ago #

    Had some time to work on this tonight and am having some luck, but having problems adding in an else or else if statement.

    I changed this line in header.php of the Twenty Eleven theme:

    <img src="<?php header_image(); ?>" width="<?php echo HEADER_IMAGE_WIDTH; ?>" height="<?php echo HEADER_IMAGE_HEIGHT; ?>" alt="Swanson Heritage" />

    to:

    <?php if( is_category ('betty') ) : ?>
    <img src="http://swansonheritage.com/wp-content/uploads/2011/07/betty_cover.jpg" width="<?php echo HEADER_IMAGE_WIDTH; ?>" height="<?php echo HEADER_IMAGE_HEIGHT; ?>" alt="Betty" />
    <?php else : ?>
    <img src="<?php header_image(); ?>" width="<?php echo HEADER_IMAGE_WIDTH; ?>" height="<?php echo HEADER_IMAGE_HEIGHT; ?>" alt="Swanson Heritage" />
    <?php endif; ?>

    And I do see the desired header image now on all the category pages in the category desired. (I will work next on how to assign this to all posts in that category also)

    I need to add multiple additional else or elseif statements below the first if to assign additional header images per category, but keep getting syntax errors.

    Any thoughts?

    And,

    @David, I have a full unmodified and renamed copy of the default theme uploaded, it would take a minute to rename it and get back to the default theme (which I do when I do core WP updates)...and I do use child themes on sites (example), I am just trying to work with this now and will create a working child theme with this once I get it right, and use that also for other sites.

  7. Pioneer Valley Web Design
    Member
    Posted 1 year ago #

    OK, now I have the else if working using:
    <?php elseif( in_category ('my-category') ) : ?>

    Still a few things to tweak but it does work.

    NOTE: changed all to in_category and am using some arrays.

  8. biieckert
    Member
    Posted 1 year ago #

    @Digital Raindrops

    I installed your second child theme, but it's not working. Can I touch base with you about getting it working?

    bizybee.com

    Thanks in advance

Topic Closed

This topic has been closed to new replies.

About this Topic