Php wordpress中自定义文章类型的分页

Php wordpress中自定义文章类型的分页,php,wordpress,pagination,custom-post-type,Php,Wordpress,Pagination,Custom Post Type,我试图在wordpress中的自定义帖子中设置分页。我的自定义帖子类型名称是视频。它显示分页,但当我单击分页页面时,它会转到404页面 <?php $videos= new WP_Query(array( 'post_type'=>'videos', 'posts_per_page' => 9, ));?> <?php if($videos->have_posts()) : ?> <?php while($video

我试图在wordpress中的自定义帖子中设置分页。我的自定义帖子类型名称是视频。它显示分页,但当我单击分页页面时,它会转到404页面

<?php 
$videos= new WP_Query(array(
    'post_type'=>'videos',
    'posts_per_page' => 9,

));?>


<?php if($videos->have_posts()) : ?>
    <?php while($videos->have_posts())  : $videos->the_post(); ?>
        <div class="col-xs-12 col-sm-6 col-md-4 col-lg-4">
            <div class="video">
                <?php the_post_thumbnail(); ?>
                <div class="watch">
                    <a href="<?php the_permalink(); ?>"><i class="fa fa-play"></i></a>
                </div>
            </div>
            <div class="video-exerpt">
                <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
            </div>
        </div>

    <?php endwhile; ?>
    <div class="col-xs-12 text-center">
        <?php
            $GLOBALS['wp_query'] = $videos; 

            the_posts_pagination(
                array(
                    'mid_size' => '2',
                    'prev_text' => '<i class="fa fa-hand-o-left"></i> Previous',
                    'next_text' => 'Next <i class="fa fa-hand-o-right"></i>',
                    'screen_reader_text' => ' '
                    )
            );
        ?>
    </div>
<?php else :?>
    <h3><?php _e('404 Error&#58; Not Found', 'Bangladesh Parjatan'); ?></h3>
<?php endif; ?>
<?php wp_reset_postdata();?>


像这样传递wp_查询参数。您应该使用分页参数进行分页

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
  $videos= new WP_Query(array(
                        'post_type'=>'videos',
                        'posts_per_page' => 9,
                        'paged' => $paged,
                    ));

希望您的分页工作正常。

您能替换下面的代码吗

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

$videos= new WP_Query(array(
    'post_type'=>'videos',
    'posts_per_page' => 9,
    'paged' => $paged,
)); ?>

<?php if($videos->have_posts()) : ?>
<?php while($videos->have_posts())  : $videos->the_post(); ?>
<div class="col-xs-12 col-sm-6 col-md-4 col-lg-4">
    <div class="video">
        <?php the_post_thumbnail(); ?>
        <div class="watch">
            <a href="<?php the_permalink(); ?>"><i class="fa fa-play"></i></a>
        </div>
    </div>
    <div class="video-exerpt">
        <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
    </div>
</div>

<?php endwhile; ?>            
    <?php 
    $total_pages = $videos->max_num_pages;

    if ($total_pages > 1){

        $current_page = max(1, get_query_var('paged'));

        echo paginate_links(array(
            'base' => get_pagenum_link(1) . '%_%',
            'format' => '/page/%#%',
            'current' => $current_page,
            'total' => $total_pages,
            'prev_text'    => __('« prev'),
            'next_text'    => __('next »'),
        ));
    }
    ?>    
<?php else :?>
<h3><?php _e('404 Error&#58; Not Found', 'Bangladesh Parjatan'); ?></h3>
<?php endif; ?>
<?php wp_reset_postdata();?>

请尝试以下代码:



您能在此处显示分页链接的呈现html吗?您已经为按钮生成了文本,但没有生成链接。看一看,当我点击第二页时,它会显示按钮bt中的链接,然后转到404.php页面。。。。。。。。请查看屏幕截图您的帖子类型名称和页面长度相同?如果相同,则从帖子类型名称更改页面长度。@saift0014您有什么解决方案吗?@saift0014好的,如果答案有帮助,请接受它。您可能有一个正确的答案,但请在回答问题时解释您的代码