可以在静态网站的主页上显示WordPress博客的缩略图和最近的帖子吗?

时间:2018-10-15 作者:Pawan Mall

请帮我弄清楚我想展示的thumbnails along with recent post from a wordpress blog on static website\'s homepage.

以下代码工作正常,但我需要将帖子中的一幅图像显示为缩略图:

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

enter image description here

But I want to show like this :-

enter image description here

enter image description here零三e>

I\'m getting following output where I\'m unable to see date in a single post:-

enter image description here

2 个回复
最合适的回答,由SO网友:Pratik Patel 整理而成

以下更新答案

<?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>
如果有任何疑问,请尝试让我知道。

SO网友:Pratik Patel

使用get_the_post_thumbnail 获取帖子特色图像的功能,如

echo get_the_post_thumbnail( $post->ID );
对于小内容使用the_excerpt 功能类似

the_excerpt();
希望它能帮助你!

结束

相关推荐