我有一个网站,在那里,我起诉wordpress代码,以放置较旧的帖子和更新的帖子,但它不会有效果。我不太擅长调试代码。有人能帮帮我吗。我也读过很多关于这方面的文章和帖子,但是我没有得到回答,希望有人能帮助我。非常感谢
<div id="main" class="blog-list-page">
<div class="container">
<div class="section">
<?php while ( have_posts() ) : the_post(); ?>
<article <?php post_class(); ?>>
<header class="page-header">
<!--<h1 class="page-title"><?php //the_title(); ?></h1>-->
</header>
<div class="entry-content">
<?php the_content(); ?>
</div>
</article>
<?php endwhile; ?>
</div>
<div class="section blog-posts-list">
<?php
$args = [
'posts_per_page' => 10,
'offset' => 0,
'orderby' => 'post_date',
'order' => 'DESC',
'post_type' => 'post',
'post_status' => 'publish',
];
$posts= get_posts( $args );
foreach ( $posts as $post ) :
setup_postdata($post);
?>
<article class="clearfix">
<div class="post-category">
<?php
$categories = get_the_category();
echo $categories[0]->name;
?>
</div>
<a href="<?= the_permalink(); ?>">
<h2><?php the_title(); ?></h2>
</a>
<div class="meta">
<span class="author"></span>
<span class="timestamp"></span>
</div>
<?php if (has_post_thumbnail()) : ?>
<a href="<?= the_permalink(); ?>" class="post-thumbnail">
<?= the_post_thumbnail(); ?>
</a>
<?php endif; ?>
<div class="excerpt">
<?php the_excerpt(); ?>
</div>
<div>
<a href="<?= the_permalink(); ?>" class="read-more-link">Read more...</a>
</div>
</article>
<?php
endforeach;
?>
</div>
</div>
</div>发布于 2015-07-01 06:22:04
不要将get_posts用于分页查询,因为它不是用于分页查询的。get_posts通过将no_found_rows=true传递给WP_Query,合法地打破了分页,以加快非分页查询。而且,get_posts只从WP_Query对象返回$posts属性,因此这一切都使得对get_posts的分页完全是一场噩梦。
对于分页查询,您应该使用WP_Query。
额外资源
https://stackoverflow.com/questions/31150866
复制相似问题