SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Wizard lukeurtnowski's Avatar
    Join Date
    Mar 2003
    Location
    Coronado
    Posts
    1,582
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    assign a featured image to a category

    I have a category at
    http://fixmysite.us/gmpc/wordpress/?cat=7
    If you notice, the featured image (the third wide one on the right in the header).
    Is there a way I can assign it a featured image (like I can a page) cause right now, its random image and I want to make it a specific image.

    Thanks...
    "Oh, and Jenkins--apparently your mother died this morning."

  2. #2
    SitePoint Enthusiast
    Join Date
    Feb 2012
    Location
    New Delhi
    Posts
    34
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Through use of custom field or check wordpress org, there may be some plugins.

  3. #3
    SitePoint Wizard lukeurtnowski's Avatar
    Join Date
    Mar 2003
    Location
    Coronado
    Posts
    1,582
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    ok, im pretty new with wordpress and want to understand the logic here.So the featured image is called by the header.php file, so I found the code that spits it out, and altered it to check for categories 5,6, and 7so am I on the right track
    (heres the altered code in my header.php file
    PHP Code:
    <?php
    // Check if this is a post or page, if it has a thumbnail, and if it's a big one
    if ( is_singular() && current_theme_supports'post-thumbnails' ) && has_post_thumbnail$post->ID ) && ( /* $src, $width, $height */ $image =  wp_get_attachment_image_srcget_post_thumbnail_id$post->ID ), 'post-thumbnail' ) ) &&
    $image[1] >= HEADER_IMAGE_WIDTH ) :
    // Houston, we have a new header image!
    echo get_the_post_thumbnail$post->ID );
    elseif ( 
    get_header_image() ) : ?>
    <img src="<?php header_image(); ?>" width="<?php echo HEADER_IMAGE_WIDTH?>" height="<?php echo HEADER_IMAGE_HEIGHT?>" alt="" />
    <?php //check for category 5
    elseif ( is_category'5' ) ) : ?>
    <img src="path/to/cat5_featuredimage.png" width="<?php echo HEADER_IMAGE_WIDTH?>" height="<?php echo HEADER_IMAGE_HEIGHT?>" alt="" />
    <?php //check for category 6
    elseif ( is_category'6' ) ) : ?>
    <img src="path/to/cat6_featuredimage.png" width="<?php echo HEADER_IMAGE_WIDTH?>" height="<?php echo HEADER_IMAGE_HEIGHT?>" alt="" />
    <?php //check for category 7
    elseif ( is_category'7' ) ) : ?>
    <img src="path/to/cat7_featuredimage.png" width="<?php echo HEADER_IMAGE_WIDTH?>" height="<?php echo HEADER_IMAGE_HEIGHT?>" alt="" />
    <?php endif; ?>
    "Oh, and Jenkins--apparently your mother died this morning."

  4. #4
    SitePoint Enthusiast OMGCarlos's Avatar
    Join Date
    Apr 2012
    Location
    Boston, MA
    Posts
    91
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Looks like it would do the trick. If not, try reordering the elseif's like so (keep the most important stuff closer to the top of the if...else block):

    PHP Code:
    <?php
    // Check if this is a post or page, if it has a thumbnail, and if it's a big one
    if ( is_category'5' ) ) : ?>
    <img src="path/to/cat5_featuredimage.png" width="<?php echo HEADER_IMAGE_WIDTH?>" height="<?php echo HEADER_IMAGE_HEIGHT?>" alt="" />
    <?php //check for category 6
    elseif ( is_category'6' ) ) : ?>
    <img src="path/to/cat6_featuredimage.png" width="<?php echo HEADER_IMAGE_WIDTH?>" height="<?php echo HEADER_IMAGE_HEIGHT?>" alt="" />
    <?php //check for category 7
    elseif ( is_category'7' ) ) : ?>
    <img src="path/to/cat7_featuredimage.png" width="<?php echo HEADER_IMAGE_WIDTH?>" height="<?php echo HEADER_IMAGE_HEIGHT?>" alt="" />
    elseif ( is_singular() && current_theme_supports( 'post-thumbnails' ) && has_post_thumbnail( $post->ID ) && ( /* $src, $width, $height */ $image =  wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'post-thumbnail' ) ) && $image[1] >= HEADER_IMAGE_WIDTH ) :
    // Houston, we have a new header image!
    echo get_the_post_thumbnail( $post->ID );
    elseif ( get_header_image() ) : ?>
    <img src="<?php header_image(); ?>" width="<?php echo HEADER_IMAGE_WIDTH?>" height="<?php echo HEADER_IMAGE_HEIGHT?>" alt="" />
    <?php //check for category 5
    elseif 
    <?
    php endif; ?>

  5. #5
    SitePoint Wizard lukeurtnowski's Avatar
    Join Date
    Mar 2003
    Location
    Coronado
    Posts
    1,582
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    k, worked rearranging the if statements like you did...
    Thank you...
    "Oh, and Jenkins--apparently your mother died this morning."


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •