在WordPress中,我目前使用下面的代碼來顯示testimonials
頁面的內容和來自自定義帖子類型testimonials
的帖子。WordPress添加分頁到自定義帖子類型
我想添加分頁但無濟於事,沒有錯誤出現,他們只是不顯示。我猜這可能與我使用兩個循環而必須重置的事實有關,但我不確定?
如需更多信息,請詢問。
<?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(); ?>
你確定你有足夠的職位,構成分頁? – 2014-10-27 10:46:37
是的,我有300多! – Giles 2014-10-27 10:51:44