[英]Cannot display 5 posts at the page using custom widget in 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_content
和post_title
没有显示在页面中。 为什么?
请使用“ echo”
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
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.