Php WordPress将分页添加到自定义帖子类型

Php WordPress将分页添加到自定义帖子类型,php,pagination,wordpress,Php,Pagination,Wordpress,在WordPress中,我目前使用下面的代码来显示推荐信页面的内容和自定义帖子类型推荐信中的帖子 我正在尝试添加分页,但没有效果,没有出现错误,它们只是不显示。我猜这可能与我使用了两个循环并且必须重置有关,但我不确定 如需更多信息,请咨询 <?php /* Template Name: Testimonials */ get_header(); ?> <div id="main"> <div class="fullwidth">

在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('&laquo; Previous') ?></div>

                <div class="alignright"><?php next_posts_link('More &raquo;') ?></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();
    


    你确定你有足够的帖子组成分页吗?是的,我有300多篇!用你的代码我似乎得到了,我不知道为什么<代码>解析错误:语法错误,第60行出现意外的'endwhile'(T_endwhile)
显然,我没有使用前面的代码得到错误!我觉得您已经用$query替换了while循环,请添加
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();