php 分页链接无效 /page/2 - NOT FOUND - Wordpress

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18744469/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 18:08:37  来源:igfitidea点击:

Pagination link is not working /page/2 - NOT FOUND - Wordpress

phpwordpresspaginationhttp-status-code-404

提问by gabrielbuzzi

I need to create a paginator in my blog page, until this its good, but when i click in a link of my pagination i got NOT FOUND page, i need to know if i need to able something in the panel to wordpress able the access to ?page=N

我需要在我的博客页面中创建一个分页器,直到这很好,但是当我点击我的分页链接时,我没有找到页面,我需要知道我是否需要在面板中设置一些东西来让 wordpress 能够访问到 ?page=N

function:

功能:

    function get_pagination($the_query) {
    global $paged;
    $total_pages = $the_query->max_num_pages;
    $big = 999999999;

    if ($total_pages > 1) {
        ob_start();

        echo paginate_links( array(
            'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
            'format' => '/page/%#%',
            'current' => $paged,
            'total' => $total_pages,
            'prev_text' => '',
            'next_text' => ''
        ));
        return ob_get_clean();
    }
    return null;
}

my blog code

我的博客代码

$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
        // echo $paged;
        $produtos = new WP_Query(array(
            'post_type'      => 'blog',
            'posts_per_page' => 1,
            'orderby'        => 'date',
            'order'          => 'asc',
            'paged'          => $paged,
            'tax_query'      => array(
                array(
                    'taxonomy' => 'categorias',
                    'field'    => 'slug',
                    'terms'    => ACTIVE
                )
            )
        ));

        while ( $produtos->have_posts() ) : $produtos->the_post();

        //CONTENT

        endwhile;

        echo get_pagination($produtos);

回答by Bashar Nozibulla

Go to admin Dashboard then Settings->Readingthen set Blog pages show at mostis equal to you query posts_per_page. So in your query if you set posts_per_page => 2then Blog pages show at mostwill be 2

转到管理仪表板,然后Settings->Reading设置Blog pages show at most等于您的查询posts_per_page。所以在你的查询中,如果你设置了posts_per_page => 2那么Blog pages show at most将是2

回答by user2958620

This is what I found and resolved the issue I had!

这就是我发现并解决了我遇到的问题!

[...] I needed to go into the wp-admin page (the wordpress dashboard) and go to Settings then Reading and in the "Blog pages show at most" field I changed the value from '10' to '6' (the number of posts I indicated in $wp_query->query('showposts=6&cat=1'.'&paged='.$paged);)

[...] 我需要进入 wp-admin 页面(wordpress 仪表板)并转到设置然后阅读,在“博客页面最多显示”字段中,我将值从“10”更改为“6”(我在$wp_query->query('showposts=6&cat=1'.'&paged='.$paged);) 中指出的帖子数量

回答by Jay Sheth

Please check your .htaccess file. It should contain a rewrite rule to enable pagination with slashes.

请检查您的 .htaccess 文件。它应该包含一个重写规则以启用带斜杠的分页。

Please see: "Using pretty permalinks" - http://codex.wordpress.org/Using_Permalinks

请参阅:“使用漂亮的永久链接” - http://codex.wordpress.org/Using_Permalinks

回答by Jothi Kannan

use following paged query

使用以下分页查询

if ( get_query_var('paged') ) { $paged = get_query_var('paged'); }
elseif ( get_query_var('page') ) { $paged = get_query_var('page'); }
else { $paged = 1; }

    $produtos = new WP_Query(array(
            'post_type'      => 'blog',
            'posts_per_page' => -1,
            'orderby'        => 'date',
            'order'          => 'asc',
            'paged'          => $paged,
            'tax_query'      => array(
                array(
                    'taxonomy' => 'categorias',
                    'field'    => 'slug',
                    'terms'    => ACTIVE
                )
            )
        ));

        while ( $produtos->have_posts() ) : $produtos->the_post();

        //CONTENT

        endwhile;

        echo get_pagination($produtos);

回答by Talha

Go to your wordpress Dashboard Settings then Reading and in the "Blog pages show at most" field, changed the value from '10' to '1' cheers!

转到您的 wordpress 仪表板设置,然后阅读并在“博客页面最多显示”字段中,将值从“10”更改为“1”!