admin管理员组文章数量:1289831
I am having problem with Custom post type paging. Clicking on 2nd page of paging through back to home page. Permalinks flush/refreshed and i am using simple code to show custom post.
following is my code
$cpt_type = get_the_title();
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
$custom_terms = get_terms('types');
$args = array('posts_per_page' => 4, 'post_type' => $cpt_type, 'paged' => $paged, 'order', 'desc'/*, 'tax_query' => array( array('taxonomy' => 'type', 'field' => 'slug', 'terms' => $custom_term->slug ))*/);
$customPostQuery = new WP_Query($args);
if($customPostQuery->have_posts() ):
while($customPostQuery->have_posts()) : $customPostQuery->the_post();
global $post;
<h4>Terms: <?php $custom_term->name; ?></h4>
<h3 class ="cq-h3"><a href="<?php the_permalink(); ?>" ><?php the_title(); ?></a></h3>
<a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('thumbnail'); ?></a>
<p><?php echo the_content(); ?></p>
endwhile;
function cpt_pagination($pages = '', $range = 4){
$showitems = ($range * 2)+1;
global $paged;
if(empty($paged)) $paged = 1;
if($pages == ''){
global $wp_query;
$pages = $wp_query->max_num_pages;
if(!$pages){
$pages = 1;
}
}
if(1 != $pages){
echo "<nav aria-label='Page navigation example'> <ul class='pagination'> <span>Page ".$paged." of ".$pages."</span>";
if($paged > 2 && $paged > $range+1 && $showitems < $pages) echo "<a href='".get_pagenum_link(1)."'>« First</a>";
if($paged > 1 && $showitems < $pages) echo "<a href='".get_pagenum_link($paged - 1)."'>‹ Previous</a>";
for ($i=1; $i <= $pages; $i++){
if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems )){
echo ($paged == $i)? "<li class=\"page-item active\"><a class='page-link'>".$i."</a></li>":"<li class='page-item'> <a href='".get_pagenum_link($i)."' class=\"page-link\">".$i."</a></li>";
}
}
if ($paged < $pages && $showitems < $pages) echo " <li class='page-item'><a class='page-link' href=\"".get_pagenum_link($paged + 1)."\">i class='flaticon flaticon-back'></i></a></li>";
if ($paged < $pages-1 && $paged+$range-1 < $pages && $showitems < $pages) echo " <li class='page-item'><a class='page-link' href='".get_pagenum_link($pages)."'><i class='flaticon flaticon-arrow'></i></a></li>";
echo "</ul></nav>\n";
}
}
if (function_exists("cpt_pagination")) {
cpt_pagination($customPostQuery->max_num_pages);
}
kindly correct me where i've placed wrong code. my cpt is 'lectures'
本文标签: Custom post type paging return home page
版权声明:本文标题:Custom post type paging return home page 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741480797a2381158.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论