2

我在 wordpress 中使用 post 查询,但分页不起作用,我不知道问题出在哪里,但这是我的代码,我想它是正确的,没有问题

它显示有页面但是当我单击下一页时它刷新页面并且不显示任何新结果只是同一页面。

我在静态页面上使用它作为我的主题的主页

<?php

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;

$post_query = query_posts(array(
    'post_type'      => 'cover', // You can add a custom post type if you like
    'paged'          => $paged,
    'posts_per_page' => 1
));

?>

<?php if ( have_posts() ) : ?>

<?php
while ( have_posts() ) : the_post(); 
?>

<?php endwhile; ?>

///Pagination Function in Functions.php
<?php my_pagination(); ?>

<?php else: ?>

    No Results

<?php endif; ?>

分页功能

if ( ! function_exists( 'my_pagination' ) ) :
    function my_pagination() {
        global $wp_query;

        $big = 999999999; // need an unlikely integer

        echo paginate_links( array(
            'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
            'format' => '?paged=%#%',
            'current' => max( 1, get_query_var('paged') ),
            'total' => $wp_query->max_num_pages
        ) );
    }
endif;
4

2 回答 2

3

经过大量搜索和谷歌搜索后的Wordpress静态首页分页我通过使用修复它

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args=array('post_type'=>'cover','posts_per_page'=>2,'paged'=>$paged);


query_posts($args);
于 2013-12-18T01:59:14.987 回答
0

我在 Youssef Subehis 解决方案中发现了一个小错误。这里的“paged”中缺少一个“d” get_query_var('page')。这为我解决了 wordpress 页面分页问题:

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array('posts_per_page'=>10,'paged'=>$paged);

query_posts($args);

这是官方 wordpress 文档中的参考

于 2016-01-11T13:42:23.250 回答