【发布时间】:2014-06-23 03:43:42
【问题描述】:
我正在使用 2 个自定义查询在自定义 Wordpress 模板主页上加载帖子。 第一个查询加载 4 个“粘性”帖子,下一个查询加载几个最近的帖子。
这很好用,可以满足我的需要,但是点击时分页链接在每个页面上显示相同的内容。
例如,我在主页上有 10 个帖子,当我点击第 2 页时 - 完全相同的 10 个帖子再次出现。如果我点击分页访问第 3 页,同样的 10 个帖子再次等。 无论我在哪个页面上,都会列出相同的 10 个帖子。
我已经阅读了一些关于需要分页的内容,但是几次尝试将其包含在下面的代码中都失败了。
任何想法表示赞赏!
我的代码...
<?php $sticky = get_option( 'sticky_posts' );
$args = array(
'posts_per_page' => 4,
'post__in' => $sticky,
'ignore_sticky_posts' => 1,
); ?>
<?php $the_query = new WP_Query( $args ); ?>
<?php if ( $the_query->have_posts() ) : ?>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<a href="<?php the_permalink() ?>"<?php the_title(); ?>"></a>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
<?php else: ?>
<p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>
<main id="main" class="site-main" role="main">
<?php $the_query = new WP_Query( array( 'post__not_in' => get_option( 'sticky_posts' ) ) );
if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<?php get_template_part( 'content', get_post_format() ); ?>
<?php endwhile; ?>
<?php else : ?>
<?php get_template_part( 'content', 'none' ); ?>
<?php endif; ?>
【问题讨论】:
标签: php loops pagination wordpress