我用 WP_query 循环在首页检索了最新的帖子,因为我发现这是最好的解决方案。但我想显示帖子在首页被点击。
单个帖子查询的最佳方法是什么?
我在 single.php 中再次使用了 wp_query(有什么更好的主意吗?)
$args = array('name' => $the_slug,
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => 1);
$the_query = new WP_Query( $args );
<?php while ( $the_query->have_posts() ) :?>
<?php $the_query->the_post(); ?>
<p><?php $content = get_the_content('Read more');
print $content; ?></p>
<?php endwhile; ?><!-- end of the loop -->
<!-- put pagination functions here -->
<?php wp_reset_postdata(); ?>
<?php else: ?>
<p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>
问题是它总是检索最新的帖子,即使我点击任何帖子 ID。我该如何解决这个问题?