[英]WordPress add Pagination to custom post type
在WordPress中,我目前正在使用以下代码来显示testimonials
页面的内容和自定义帖子类型testimonials
的帖子。
我正在尝试添加分页,但无济于事,没有出现错误,只是没有显示。 我猜这可能与我正在使用两个循环并必须重置的事实有关,但是我不确定?
需要更多信息请询问。
<?php /* Template Name: Testimonials */ get_header(); ?>
<div id="main">
<div class="fullwidth">
<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
<h1><?php the_field('h1_title'); ?></h1>
<div class="width">
<ul class="menu slider">
<?php if(wp_list_pages('child_of='.$post->ID.'&echo=0&exclude=2')) { $list_of_pages = wp_list_pages('echo=0&title_li=&depth=1&child_of='.$post->ID.'&exclude=2'); $list_pages = explode('<li class="',$list_of_pages); $len = count($list_pages); for ($i = 0; $i <= $len-2; $i++) : echo $list_pages[$i] . '<li class="list-item-' . ($i+1) . ' '; endfor; echo $list_pages[$i]; }
elseif(get_the_title($post->post_parent) != the_title(' ' , ' ',false)) { $list_of_pages = wp_list_pages('echo=0&title_li=&depth=1&child_of='.$post->post_parent.'&title_li=&exclude=2'); $list_pages = explode('<li class="',$list_of_pages); $len = count($list_pages); for ($i = 0; $i <= $len-2; $i++) : echo $list_pages[$i] . '<li class="list-item-' . ($i+1) . ' '; endfor; echo $list_pages[$i]; } ?>
</ul>
</div>
<h2><?php the_field('h2_title'); ?></h2>
<?php the_content(); ?>
<?php endwhile; wp_reset_postdata(); ?>
<div class="posts">
<?php $query = new WP_Query( array ( 'post_type' => 'testimonial', 'order' => 'DESC', 'posts_per_page' => 9, 'orderby'=> menu_order ) ); while ( $query->have_posts() ) : $query->the_post(); ?>
<div class="blog-post">
<div class="content">
<h3><?php the_title();?></h3>
<h4><?php the_field('visit_date'); ?></h4>
<?php the_content(); ?>
</div>
<div class="clear"></div>
</div>
<?php endwhile; ?>
<div class="navigation">
<div class="alignleft"><?php previous_posts_link('« Previous') ?></div>
<div class="alignright"><?php next_posts_link('More »') ?></div>
</div>
</div>
</div>
<?php get_footer(); ?>
我觉得您没有获取并传递页面#,尝试像这样更改/替换您的代码
$query = new WP_Query( array ( 'post_type' => 'testimonial', 'order' => 'DESC', 'posts_per_page' => 9, 'orderby'=> menu_order ) ); while ( $query->have_posts() ) : $query->the_post();
至
$page = (get_query_var('paged')) ? get_query_var('paged') : 1;
$query = new WP_Query( array ( 'post_type' => 'testimonial', 'order' => 'DESC', 'posts_per_page' => 9, 'orderby'=> 'menu_order','paged' => $page ) );
while ( $query->have_posts() ) : $query->the_post();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.