Community Forums › Forums › Archived Forums › Design Tips and Tricks › different sized featured image on first post on first page only
Tagged: featured, featured image, featured post image, first, first post, image, size
- This topic has 11 replies, 3 voices, and was last updated 10 years, 2 months ago by wickedsimple.
-
AuthorPosts
-
August 9, 2014 at 6:18 pm #118002kittyridgeMember
I'm trying to create a bit of code to put into functions.php that will change the size of the featured image only on the first post on the first page at doesthishousemakemelookfat.com. This is what I've come up with, which isn't working. Any help appreciated:
http://www.doesthishousemakemelookfat.comremove_action( 'genesis_post_content', 'genesis_do_post_image' ); add_action('genesis_post_content','first_post_image') ; function first_post_image() { global $query_string; query_posts($query_string . '&meta_key=_thumbnail_id&meta_compare=EXISTS' ); // will only query posts with thumbnails if( have_posts() ) : $i = 0; while( have_posts() ) : the_post(); $i++; // count if( !$paged && $i == 1) { // assumes you already have a $paged-variable and it is not set the_post_thumbnail( 'full' ); // print a big image for the first post } else { the_post_thumbnail( 'thumbnail' ); // print thumbnails for the rest } endwhile; endif; }
August 17, 2014 at 11:10 pm #119458Brad DaltonParticipantThis may help http://www.billerickson.net/code/first-post-class/
You could change the $opt to a different size image or custom size.
August 18, 2014 at 12:20 am #119465Brad DaltonParticipantHere's a full solution which is flexible http://wpsites.net/web-design/customize-the-first-featured-image-in-the-home-page-loop/
August 18, 2014 at 12:19 pm #119572kittyridgeMemberThat did it! This function is so much more elegant and simple than what I was trying to rework. I'm using it very successfully at DoesThisHouseMakeMeLookFat.com. I'll definitely have http://wpsites.net/web-design/customize-the-first-featured-image-in-the-home-page-loop/ bookmarked for future reference. This is an extremely useful function that will come in very handy. Thanks for taking the time to throw this together!!! It will most definitely be very helpful to the StudioPress community!
August 30, 2014 at 6:38 am #121821wickedsimpleMemberHi Brad,
I came here looking for the answer to the same question! I would like the featured image in the first post on the homepage to be full size. I copied the code in your link above http://wpsites.net/web-design/customize-the-first-featured-image-in-the-home-page-loop/ to my functions.php page and then as a test, I put in your sample CSS:
.first-image {
height: 360px;
}but nothing happened. I would like that first image to be full size as my client sometimes has an image as her blog post (without any additional text).
Donna
August 30, 2014 at 6:47 am #121825Brad DaltonParticipantHello Donna
Whats happens if you change the size in the code from thumbnail to full?
August 30, 2014 at 7:04 am #121829Brad DaltonParticipantAugust 30, 2014 at 7:08 am #121835wickedsimpleMemberThis is where I changed it:
add_filter( 'genesis_get_image_default_args', 'filter_first_featured_image_loop' );
/**
* @author Brad Dalton
* @example http://wpsites.net/web-design/customize-the-first-featured-image-in-the-home-page-loop/
* @copyright 2014 WP Sites
*/
function filter_first_featured_image_loop( $defaults ) {
global $wp_query;
if( 0 == $wp_query->current_post && is_home() ) :
the_post_thumbnail( 'full', array( 'class' => 'first-image' ) );
else:
return $defaults;
endif;
}But nothing happened
August 30, 2014 at 7:12 am #121838Brad DaltonParticipantI tested it locally and it works for me.
Try clearing your caching.
Do you have any plugins which modify featured images installed?
Maybe the CSS is causing issues.
Link to the site please.
August 30, 2014 at 7:19 am #121841wickedsimpleMemberCleared the cache. Checked to make sure none of the plugins modified the featured images. Still the same. This site is going to be the end of me, LOL!
Here's the link:
http://www.analisamendmentblog.com
Thanks for your help, Brad!
August 30, 2014 at 7:25 am #121843Brad DaltonParticipantThe code works on the home page loop, not widgets.
Looks like you're using featured posts widgets so you'll need to change the widget settings.
August 30, 2014 at 7:32 am #121844wickedsimpleMemberAhh....I adjusted it to show the full "excerpt", which in this case is an image and then removed the featured image and it gave me the desired result.
Thank you!!!
Donna
-
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.