Is it possible to show thumbnails along with recent post from a wordpress blog on static website's homepage?
-
13-04-2021 - |
Pregunta
Please help me to figure this out that I want to show thumbnails along with recent post from a wordpress blog on static website's homepage.
Following code are working fine but I need to show one single image from post as thumbnail:
<?php define('WP_USE_THEMES', false); require('blog/wp-blog-header.php'); ?> <?php $args = array( 'numberposts' => 3, 'post_status'=>"publish",'post_type'=>"post",'orderby'=>"post_date"); $postslist = get_posts( $args ); foreach ($postslist as $post) : setup_postdata($post);?> // Here I want to show post's thumbnail <h4 class="post-modern-title"> <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> </h4> <p class="post-short-info"> // Here I want to show post's short info </p> <?php endforeach; ?>
Right now it is showing like this :-
But I want to show like this :-
Here are the updated code :-
<?php
define('WP_USE_THEMES', false);
require('blog/wp-blog-header.php');
?>
<div class="row row-60 row-sm">
<?php
$args = array( 'numberposts' => 3, 'post_status'=>"publish",'post_type'=>"post",'orderby'=>"post_date");
$postslist = get_posts( $args );
foreach ($postslist as $post) : setup_postdata($post);?>
<div class="col-sm-6 col-lg-4 wow fadeInLeft">
<!-- Post Modern-->
<article class="post post-modern"><a class="post-modern-figure" href="<?php the_permalink( $post->ID ); ?>" target="_top">
<?php echo get_the_post_thumbnail( $post->ID ); ?>
<div class="post-modern-time">
<!-- <time datetime=""><span class="post-modern-time-month">07</span><span class="post-modern-time-number">04</span></time> -->
<time datetime=""><span class="post-modern-time-number"><?php echo the_date( 'd/m' ); ?></span></time>
</div></a>
<h4 class="post-modern-title"><a href="<?php the_permalink( $post->ID ); ?>" target="_top"><?php the_title(); ?></a></h4>
<p class="post-modern-text"><?php the_excerpt(); ?></p>
</article>
</div>
<?php endforeach; ?>
</div>
I'm getting following output where I'm unable to see date in a single post:-
Solución
Updated answer below
<?php
define('WP_USE_THEMES', false);
require('blog/wp-blog-header.php');
?>
<div class="row row-60 row-sm">
<?php
$args = array( 'numberposts' => 3, 'post_status'=>"publish",'post_type'=>"post",'orderby'=>"post_date");
$postslist = get_posts( $args );
foreach ($postslist as $post) : setup_postdata($post);?>
<div class="col-sm-6 col-lg-4 wow fadeInLeft">
<!-- Post Modern-->
<article class="post post-modern"><a class="post-modern-figure" href="<?php the_permalink( $post->ID ); ?>" target="_top">
<?php echo get_the_post_thumbnail( $post->ID ); ?>
<div class="post-modern-time">
<!-- <time datetime=""><span class="post-modern-time-month">07</span><span class="post-modern-time-number">04</span></time> -->
<time datetime=""><span class="post-modern-time-number"><?php echo get_the_date( 'd/m', $post->ID ); ?></span></time>
</div></a>
<h4 class="post-modern-title"><a href="<?php the_permalink( $post->ID ); ?>" target="_top"><?php the_title(); ?></a></h4>
<p class="post-modern-text"><?php the_excerpt(); ?></p>
</article>
</div>
<?php endforeach; ?>
</div>
Please try and let me know if any query.
Otros consejos
Use get_the_post_thumbnail function for get post featured image like
echo get_the_post_thumbnail( $post->ID );
And for small content use the_excerpt function like
the_excerpt();
Hope it will help you!
Licenciado bajo: CC-BY-SA con atribución
No afiliado a wordpress.stackexchange