单代理页面中的分页无法正常工作 [英] Pagenation in single agent page not working wordpress

查看:40
本文介绍了单代理页面中的分页无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have created a single agent page in that page i am trying to list all the property by the agent in that property area i have kept an bootstrap pagination that was not working it was showing the page numbers but when you click that was not taking to page1 or page 2 etc. But it was redirecting to the same page. Here is my code.

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

这是引导程序分页代码 Bootstrap pagenatio

Here is the link for bootstrap pagenation code Bootstrap pagenatio

推荐答案

这是您问题的答案。如果您需要在单个页面上添加分页,例如您的单个代理页面,则需要在wordpress中设置模板重定向功能,为此您需要将以下代码添加到活动主题功能中。php在此代码中,请更改代理

Here is a answer for your question. If you need to add an pagenation to your single page for example your single agent page you need to set a template redirect function in wordpress for that you need to add the following code to your active themes function.php In this code please change the agent to your custom post type if your custom post is not agent.

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

这篇关于单代理页面中的分页无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆