2017-07-15 44 views
1

我想在小部件中顯示5篇文章。我所要做的就是:無法在WordPress頁面中使用自定義小部件顯示5篇文章

$post_arguments = array(
    'posts_per_page' => 5, 
    'post_status' => 'publish', 
    'post_type'  => 'industry_news' 
); 
$posts_array = get_posts($post_arguments); 

到目前爲止好,在我的HTML我有以下的foreach:

foreach ($posts_array as $single_post) { 
      ?> 
      <ul class="tabs-content"> 
       <li class="tab-active"> 
        <div class="article"><a href="#"><img width="260" height="140" class="wp-post-image" alt=""></a> 
         <h3 class="title"> 
          <a href="http://example.com/example" 
           title=""><?php $single_post->post_title ?></a> 
         </h3> 
         <p><?php $single_post->post_content ?></p> 
        </div> 
       </li> 
      </ul> 
     </div> 
     <?php 
     } 

的問題是,post_contentpost_title沒有在頁面顯示。爲什麼?

+0

請使用 '迴響' – Arun

回答

2

請使用 '迴響'

foreach ($posts_array as $single_post) { 
      ?> 
      <ul class="tabs-content"> 
       <li class="tab-active"> 
        <div class="article"><a href="#"><img width="260" height="140" class="wp-post-image" alt=""></a> 
         <h3 class="title"> 
          <a href="http://staging.smartmeetings.com/destinations/98313/south-carolina-food-guide" 
           title=""><?php echo $single_post->post_title ?></a> 
         </h3> 
         <p><?php echo $single_post->post_content ?></p> 
        </div> 
       </li> 
      </ul> 
     </div> 
     <?php 
     } 
相關問題