最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

Is it possible to show thumbnails along with recent post from a wordpress blog on static website's homepage?

matteradmin9PV0评论

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:-

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:-

Share Improve this question edited Oct 17, 2018 at 16:16 Pawan Mall asked Oct 15, 2018 at 22:05 Pawan MallPawan Mall 33 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 0

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.

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!

Post a comment

comment list (0)

  1. No comments so far