单代理页面中的分页不工作wordpress

单代理页面中的分页不工作wordpress,wordpress,custom-post-type,Wordpress,Custom Post Type,我在该页面中创建了一个单独的代理页面。我试图列出该代理在该属性区域中的所有属性。我保留了一个引导分页,该分页不起作用。它显示了页码,但当您单击该页时,它没有转到第1页或第2页等。但它重定向到了同一页。这是我的密码 get_header(); <div class="container-fluid"><div class="row bkg-white bkg-pd-top"> <div class="container"> <?php if (have_p

我在该页面中创建了一个单独的代理页面。我试图列出该代理在该属性区域中的所有属性。我保留了一个引导分页,该分页不起作用。它显示了页码,但当您单击该页时,它没有转到第1页或第2页等。但它重定向到了同一页。这是我的密码

get_header();
<div class="container-fluid"><div class="row bkg-white bkg-pd-top">
<div class="container">
<?php if (have_posts()) : 
while (have_posts()) : the_post(); ?>
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?> >
    <div class="col-md-9"><div class="row">
<div class="single-details">
<div class="single-sec-prop-title">Agent Details</div>
<div class="single-prop-detail">
<div class="col-md-4 col-sm-4 col-xs-4"><div class="row"><div class="agent-single-image">
<?php the_post_thumbnail('small-img-featured', array('class' => 'img-responsive')); ?>
</div></div></div>
</div>
</div></div>    
</div></div>

<div class="single-details">
<div class="single-sec-prop-title">Description</div>
<div class="single-prop-detail">   
<?php the_content(); ?>
</div>
</div>

<div class="col-xs-12"><div class="row">
<div class="single-sec-prop-title agent-single-title">Listed Properties</div>
<?php
endwhile; 
endif;

if (get_query_var('paged')) {
    $paged = get_query_var('paged');
} elseif (get_query_var('page')) { 
    $paged = get_query_var('page');
} else {
    $paged = 1;
}
$args = array(
'post_type' => array('forsale', 'forrent'),
'numberposts' => -1,
'posts_per_page' => 10,
'post_status' => 'publish',
'paged' => $paged,  //very important
'meta_key' => 'select-agent',
'meta_value' => get_the_id(),
);
$custom_query = new WP_Query($args);
if ($custom_query->have_posts()) :
while ($custom_query->have_posts()) : $custom_query->the_post();
get_template_part( 'template-parts/property', 'agent' );  
endwhile;  ?>
<?php 
if ($custom_query->max_num_pages > 1) :
$orig_query = $wp_query;
$wp_query = $custom_query;
?><nav class="prev-next-posts">
<?php
if (function_exists('wp_bootstrap_pagination')){
wp_bootstrap_pagination();
}
?>
</nav>
<?php endif;
 wp_reset_postdata();
else:
 get_template_part( 'template-parts/no', 'post' ); 
endif;  //ends loop

?>

<?php 
get_footer(); 
get_header();

你可以用wordpress试试这个

<?php 
get_header(); ?>
<div class="container-fluid"><div class="row bkg-white bkg-pd-top">
<div class="container">
<?php if (have_posts()) : 
while (have_posts()) : the_post(); ?>
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?> >
    <div class="col-md-9"><div class="row">
<div class="single-details">
<div class="single-sec-prop-title">Agent Details</div>
<div class="single-prop-detail">
<div class="col-md-4 col-sm-4 col-xs-4"><div class="row"><div class="agent-single-image">
<?php the_post_thumbnail('small-img-featured', array('class' => 'img-responsive')); ?>
</div></div></div>
</div>
</div></div>    
</div></div>

<div class="single-details">
<div class="single-sec-prop-title">Description</div>
<div class="single-prop-detail">   
<?php the_content(); ?>
</div>
</div>

<div class="col-xs-12"><div class="row">
<div class="single-sec-prop-title agent-single-title">Listed Properties</div>
<?php
endwhile; 
endif;

if (get_query_var('paged')) {
    $paged = get_query_var('paged');
} elseif (get_query_var('page')) { 
    $paged = get_query_var('page');
} else {
    $paged = 1;
}
$args = array(
'post_type' => array('forsale', 'forrent'),
'numberposts' => -1,
'posts_per_page' => 10,
'post_status' => 'publish',
'paged' => $paged,  //very important
'meta_key' => 'select-agent',
'meta_value' => get_the_id(),
);
$custom_query = new WP_Query($args);
if ($custom_query->have_posts()) :
while ($custom_query->have_posts()) : $custom_query->the_post();
get_template_part( 'template-parts/property', 'agent' );  
endwhile;  

customPagination($paged,$custom_query);


endif;
 wp_reset_postdata();
else:
 get_template_part( 'template-parts/no', 'post' ); 
endif;  //ends loop

?>

<?php 
get_footer();

?>


<?php 
function customPagination($paged,$probj){

            $data = '';
            $data .='<nav aria-label="Page navigation example">';
                $pager = 999999999; 
                $pargs = array(
                    'base' => str_replace( $pager, '%#%', esc_url( get_pagenum_link( $pager ) ) ),
                    'format' => '?paged=%#%',
                    'current' => max( 1, $paged ),
                    'total' => $probj->max_num_pages,
                    'prev_next'=> false,
                    'type'=> 'array'
                );      
                $links = paginate_links( $pargs );              

                if ( $links ) :

                    $data .= '<ul class="pagination justify-content-center">';

                    // get_previous_posts_link will return a string or void if no link is set.
                    if ( $prev_posts_link = get_previous_posts_link( __( 'Previous Page' ) ) ) :
                        $data .= '<li class="prev-list-item">';
                        $data .= $prev_posts_link;
                        $data .= '</li>';
                    endif;

                    $data .= '<li class="page-item">';
                    $data .= join( '</li><li class="page-item">', $links );
                    $data .= '</li>';

                    // get_next_posts_link will return a string or void if no link is set.
                    if ( $next_posts_link = get_next_posts_link( __( 'Next Page' ) ) ) :
                        $data .= '<li class="next-list-item">';
                        $data .= $next_posts_link;
                        $data .= '</li>';
                    endif;
                    $data .= '</ul>';
                endif;



            $data .='</nav>';
            echo $data;
        }


?>


这是你问题的答案。如果您需要向单个页面添加页面,例如您的单个代理页面,您需要在wordpress中设置模板重定向函数,您需要将以下代码添加到活动主题函数中。php在此代码中,如果自定义帖子不是代理,请将代理更改为自定义帖子类型

 add_filter('redirect_canonical','redirect_single_page');

    function redirect_single_page($redirect_url) {
    if (is_singular('agent')) $redirect_url = false; // change 'agent' to your custom post type, obviously
    return $redirect_url;
    }

你知道为什么引导分页不起作用吗Kaushal bhatt我试过你的代码同样的问题也发生在你的代码中。