Community Forums › Forums › Archived Forums › Design Tips and Tricks › Different Feature Images on New Blog Posts
Tagged: featured image
- This topic has 4 replies, 2 voices, and was last updated 6 years, 11 months ago by pxforti.
-
AuthorPosts
-
October 11, 2017 at 7:28 am #212413pxfortiParticipant
Hi,
I am updating my genesis theme and I want to use a different sized featured image on all NEW blogs Posts.
My old featured images size was 100px wide. My new featured image size is 800px wide. As a result, I want to leave the old posts with the 100px wide featured image because the original image is 100px wide.
I realize that I can change the genesis theme setting to use a different image size, but that changes the image size on all posts.
I am trying some code that searches for posts newer than the August 1 and adds a different sized featured image to that post, but leaves the older post with the origianl 100px by 100px featured image.
Here is an example of the code I have so far. It works, but it leaves the old 100px by 100px image on the new posts:
add_action( 'genesis_entry_header', 'featured_post_image', 1 ); function featured_post_image() { global $post; if (strtotime($post->post_date) >= strtotime('2017-08-01') and ( is_singular( 'post' ) or is_category() or is_home() ) ) { the_post_thumbnail('large'); } }
Thanks
writeNowDesign
WordPress and Ecommerce Website DesignOctober 11, 2017 at 10:33 am #212417tarmadilloParticipantWhen I
echo $post->post_date
on my site, I get the year, month, day, hour, min, seconds.try
get_the_date('Y-m-d', $post->ID )
edit: now that i think about it it, the original should still be greater than the string you gave, I'll keep looking.
October 11, 2017 at 11:14 am #212420tarmadilloParticipantI need to stop jumping to conclusions lol. I did this and it worked for me.
function featured_post_image() { global $post; $day = 20170801; if ( intval(get_the_date('Ymd', $post->ID )) >= $day ) { the_post_thumbnail('large'); } else { the_post_thumbnail('thumbnail'); } }
you may have to do more stuff to make it clickable but I don't know
October 11, 2017 at 11:18 am #212421pxfortiParticipantHi, Thanks for the reply. Both date functions work. The problem I am having is that I want to remove the genesis feature image on new post using
remove_action( 'genesis_entry_content', 'genesis_do_post_image', 8 );
But that removes all genesis featured images. I only want to remove the genesis featured image from the new post and instead useadd_action( 'genesis_before_loop', 'featured_post_image', 1 ); function featured_post_image() { global $post; //if (strtotime($post->post_date) >= strtotime('2017-08-01') and ( is_singular( 'post' ) or is_category() or is_home() ) ) { $date = '2017-08-01'; if ( get_the_date('Y-m-d', $post->ID ) >= $date and ( is_singular( 'post' ) or is_category() or is_home() ) ) { the_post_thumbnail('large'); echo get_the_date('Y-m-d', $post->ID ); remove_action( 'genesis_entry_content', 'genesis_do_post_image', 8 ); } }
writeNowDesign
WordPress and Ecommerce Website DesignOctober 11, 2017 at 11:19 am #212422pxfortiParticipantThanks. That will work. Now I'll get the links in. I will post final code when I get it done.
writeNowDesign
WordPress and Ecommerce Website Design -
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.