我正在为我的 wordpress 主题制作一个 wordpress 小部件。在小部件中,我试图仅查询我正在使用的 front-page.php 上的一篇文章WP_query。但问题是它正在获取所有可用的帖子。我不知道如何解决这个问题。任何建议都会有所帮助。
我的代码
public function widget($args, $instance) {
$posts_args = array(
'post_type' => 'post',
'post_per_page' => 1,
'order' => 'DESC'
);
$posts_query = new WP_Query($posts_args);
echo $args['before_widget'];
if($posts_query -> have_posts()):
while($posts_query->have_posts()): $posts_query->the_post();
echo '<div class="widget-single-content" style="background-image: url('.get_the_post_thumbnail_url().')">';
echo '<div class="content-box">';
echo '<h1><span>"</span>'.get_the_title().'<span>"</span></h1>';
echo '<button class="readmore-btn text-captalize">
<a href="'.get_the_permalink().'">Read More</a></button>';
echo '</div>';
echo '</div>';
endwhile;
endif;
echo $args['after_widget'];
//Query
}
神不在的星期二