无法在 WordPress 中使用自定义小部件在页面上显示 5 个帖子
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
}
我正在尝试在小部件中显示 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
}