php 分页链接不工作/page/2 -未找到- Wordpress

mjqavswn  于 2023-01-12  发布在  PHP
关注(0)|答案(6)|浏览(213)

我需要在我的博客页面创建一个分页器,直到这是好的,但当我点击我的分页链接,我没有找到页面,我需要知道,如果我需要能够在面板中的东西WordPress能够访问?页面=N
功能:

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;
}

我的博客代码

$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);
wztqucjr

wztqucjr1#

转到管理控制面板,然后选择Settings->Reading,然后将Blog pages show at most设置为等于您查询的posts_per_page。因此,在您的查询中,如果您设置posts_per_page => 2,则Blog pages show at most将为2

nlejzf6q

nlejzf6q2#

这就是我发现并解决了我遇到的问题!
[...]我需要进入wp-admin页面(wordpress Jmeter 板),然后去设置阅读和在“博客页面显示最多”字段,我改变了值从'10'到'6'(我在$wp_query->query('showposts=6&cat=1'.'&paged='.$paged);中指出的职位数量)

bnl4lu3b

bnl4lu3b3#

使用以下分页查询

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);
vaj7vani

vaj7vani4#

请检查您的.htaccess文件。它应该包含一个重写规则以启用使用斜线的分页。
请参阅:“使用漂亮的固定链接”-http://codex.wordpress.org/Using_Permalinks

wmvff8tz

wmvff8tz5#

Problem: When we click on next page then wordpress redirects on first 
 -------  page or on same pag.

Solution: put this code snippet in your themes functions.php file.
--------

add_filter('redirect_canonical', 'pif_disable_redirect_canonical');

function pif_disable_redirect_canonical($redirect_url)
{
    if (is_singular()) $redirect_url = false;
    return $redirect_url;
}

 ---------------------------------------------------
! it has worked for me , I hope it works for you
qyzbxkaa

qyzbxkaa6#

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

相关问题