I would like to be able to display the blog post's thumbnail a smaller size and right floated if it was posted before April 11, 2019 but I can't seem to figure it out.
This is what I tried:
<?php
global $post;
$compare_date = strtotime( "2018-03-01" );
$post_date = strtotime( $post->post_date );
if (has_post_thumbnail() && ( $compare_date < $post_date ) ) {
echo '<div style="float:right;padding-left:20px;"><img src="'.the_post_thumbnail().'" /></div>';}
else {
echo '<img src="'.the_post_thumbnail().'" />';}
?>
But when I did this, it affected all of my post thumbnails rather than just the ones before a specific date.
Any ideas?
I would like to be able to display the blog post's thumbnail a smaller size and right floated if it was posted before April 11, 2019 but I can't seem to figure it out.
This is what I tried:
<?php
global $post;
$compare_date = strtotime( "2018-03-01" );
$post_date = strtotime( $post->post_date );
if (has_post_thumbnail() && ( $compare_date < $post_date ) ) {
echo '<div style="float:right;padding-left:20px;"><img src="'.the_post_thumbnail().'" /></div>';}
else {
echo '<img src="'.the_post_thumbnail().'" />';}
?>
But when I did this, it affected all of my post thumbnails rather than just the ones before a specific date.
Any ideas?
Share Improve this question edited Jan 31, 2020 at 7:36 fuxia♦ 107k39 gold badges255 silver badges459 bronze badges asked Jan 30, 2020 at 20:06 Brenda CareyBrenda Carey 12 bronze badges 1 |1 Answer
Reset to default -1In what way is it affecting your post thumbnails?
I cleaned up your code a bit. If you can show me the output you're getting I'll be able to help you further.
<?php
global $post;
$compare_date = strtotime( "2018-03-01" );
$post_date = strtotime( $post->post_date );
if ( has_post_thumbnail() ) {
if ( $compare_date < $post_date ) {
echo '<div style="float:right;padding-left:20px;"><img src="' . the_post_thumbnail() . '"/></div>';
}
else {
echo '<img src="' . the_post_thumbnail() . '" />';
}
}
?>
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744788023a4593744.html
get_the_post_thumbnail()
developer.wordpress/reference/functions/… in the string concatenation, and remove the image tags because the function returns the complete image tag for the featured image. – Michael Commented Jan 31, 2020 at 4:43