2017-06-13 17 views
0

我正在寻找在我的主页横幅上显示最近的帖子(不超过5个)的x(未定)数量。对于每篇文章,我想显示标题,发布日期,作者和精选图片作为内容缩略图的背景。我想知道什么是WordPress的功能来获得这个。我也想定制HTML格式。我已经得到了最接近看起来像这样如何在主页上显示最近发布的帖子,标题,发布日期,作者和精选图片作为缩略图的背景?

<!-- Post carousel --> 
      <div class="cs-post-carousel-layout"> 
       <div class="cs-container swiper-container"> 
        <div class="swiper-wrapper"> 
        <?php 

    // define query arguments 
    $args = array(
     'posts_per_page' => 8, // your 'x' goes here 
     'nopaging' => true 
     // possibly more arguments here 
    ); 

    // set up new query 
    $tyler_query = new WP_Query($args); 

    // loop through found posts 
    while ($tyler_query->have_posts()) : $tyler_query->the_post(); 
         //Post item --> 
         echo '<div class="swiper-slide">'. 
          '<div class="cs-post-item">'. 
           '<div class="cs-post-category-icon">'. 
            '<a href="'. 
            get_permalink(). 
            '"></i></a>'. 
           '</div>'. 
           '<div class="cs-post-thumb">'. 
            '<a href="post_standard.html"><img src="demo/carousel/1.jpg" alt="UniqMag"></a>'. 
           '</div>'. 
           '<div class="cs-post-inner">'. 
            '<h3><a href="'. 
            get_permalink(). 
            '">'. 
            get_the_title(). 
            '</a></h3>'. 
            //'<div class="cs-post-meta cs-clearfix">'. 
             // '<span class="cs-post-meta-author"><a href="post_standard.html">J. Doe</a></span>'. 
             // '<span class="cs-post-meta-date">Sep 19, 2015</span>'. 
            //'</div>'. 
           '</div>'. 
          '</div>'. 
         '</div>'; 
         endwhile; 

    // reset post data 
    wp_reset_postdata(); 

?> 

        </div> 
       </div> 
      </div> 

回答

相关问题