如何在子帖子列表中添加分页

发布于 2025-01-12 10:08:17 字数 3024 浏览 0 评论 0原文

我创建了一个名为“节目”的自定义帖子类型,每个节目都包含剧集 剧集将是儿童帖子 有些节目包含一百多集,所以我想在我的子帖子列表中添加分页 我已经使用 $paged = (get_query_var('page')) 进行了基本尝试? get_query_var('页面') : 1;以及 WP_Query 中的分页参数,但我的 next_posts_link 不起作用。我的代码显示子帖子

<?php

        $args = array(
            'post_type'      => 'programs',
            'posts_per_page' => 60,
            'post_parent'    => $post->ID,
            'order'          => 'ASC',
        );


        $parent = new WP_Query( $args );

        if ( $parent->have_posts() ) : ?>
        <div class="penci-border-arrow penci-homepage-title penci-magazine-title style-5 pcalign-right pciconp-right pcicon-right" style="border-color: #3E68B0">
        <h3 class="inner-arrow" style="background:#3E68B0;border-color: #3E68B0">
        الحلقات </h3>
        
        </div>
        <ul class="penci-wrapper-data penci-grid">    
            <?php while ( $parent->have_posts() ) : $parent->the_post(); 
            $featured_img_url = get_the_post_thumbnail_url(get_the_ID());
            $episode_number = get_field('episode_number', get_the_ID());
            ?>
            
            <li class="list-post pclist-layout">
            <article id="post-<?php the_ID(); ?>" class="item hentry">
            <div class="thumbnail child-thumbnail"> 
            <a class="penci-image-holder penci-lazy" href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" style="background-image: url(<?php echo $featured_img_url?>);">
            </a>
            </div>
            <div class="content-list-right content-list-center child-content">
                <div class="header-list-style">
                <div class="episode-details">
                    <span class=""> <a class="url fn n" href="<?php the_permalink(); ?>"><?php echo  $episode_number ?></a></span> 
                    <span style="margin:0 20px"><a>|</a></span>
                    <span class="featc-date"><time class="entry-date published" datetime="2021-10-31T13:26:29+00:00">2021-10-31</time>
                    </span>
                    <span class='program-viewcn'><?php pvc_stats_update( get_the_ID(), 1 ); ?></span> 
                </div>
                    <h2 class="grid-title entry-title">
                      <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
                    </h2>
                </div>
                <div class="item-content entry-content">
                    <p>
                    <?php the_excerpt();?>
                    </p>
                </div>
                
            </div>
            </article>
            </li>
            <?php endwhile; ?>
        </ul>
        <?php endif; ?> 

I created a custom post type called Programs, Each program contains episodes
Episodes will be Child Post
Some programs contain more than a hundred episodes, so I want to add pagination to my child posts list
I've had a basic attempt at this using $paged = (get_query_var('page')) ? get_query_var('page') : 1; and the paged argument in the WP_Query, but my next_posts_link doesn't work. my code to show child post

<?php

        $args = array(
            'post_type'      => 'programs',
            'posts_per_page' => 60,
            'post_parent'    => $post->ID,
            'order'          => 'ASC',
        );


        $parent = new WP_Query( $args );

        if ( $parent->have_posts() ) : ?>
        <div class="penci-border-arrow penci-homepage-title penci-magazine-title style-5 pcalign-right pciconp-right pcicon-right" style="border-color: #3E68B0">
        <h3 class="inner-arrow" style="background:#3E68B0;border-color: #3E68B0">
        الحلقات </h3>
        
        </div>
        <ul class="penci-wrapper-data penci-grid">    
            <?php while ( $parent->have_posts() ) : $parent->the_post(); 
            $featured_img_url = get_the_post_thumbnail_url(get_the_ID());
            $episode_number = get_field('episode_number', get_the_ID());
            ?>
            
            <li class="list-post pclist-layout">
            <article id="post-<?php the_ID(); ?>" class="item hentry">
            <div class="thumbnail child-thumbnail"> 
            <a class="penci-image-holder penci-lazy" href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" style="background-image: url(<?php echo $featured_img_url?>);">
            </a>
            </div>
            <div class="content-list-right content-list-center child-content">
                <div class="header-list-style">
                <div class="episode-details">
                    <span class=""> <a class="url fn n" href="<?php the_permalink(); ?>"><?php echo  $episode_number ?></a></span> 
                    <span style="margin:0 20px"><a>|</a></span>
                    <span class="featc-date"><time class="entry-date published" datetime="2021-10-31T13:26:29+00:00">2021-10-31</time>
                    </span>
                    <span class='program-viewcn'><?php pvc_stats_update( get_the_ID(), 1 ); ?></span> 
                </div>
                    <h2 class="grid-title entry-title">
                      <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
                    </h2>
                </div>
                <div class="item-content entry-content">
                    <p>
                    <?php the_excerpt();?>
                    </p>
                </div>
                
            </div>
            </article>
            </li>
            <?php endwhile; ?>
        </ul>
        <?php endif; ?> 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文