簡體   English   中英

為什么我的分頁鏈接未顯示此自定義WP查詢?

[英]Why aren't my pagination links showing for this custom WP Query?

出於某種原因,除了底部的分頁之外,其他所有操作WP_Query在此WP_Query上進行, paginate_links()不會輸出任何內容。

我不知道為什么,查詢返回所有正確的項目,而page_per_posts正常工作,我什至可以通過直接訪問URL /page/2/等來訪問其余部分。

為什么分頁沒有顯示?

// Get only the posts with Press Release category
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
$pressRelease_posts = new WP_Query(array(
    'paged'           => $paged,
    'posts_per_page'  => get_option('posts_per_page'),
    'category_name'   => 'press-releases'
));

<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    <h1 class="entry-title"><?php the_title(); ?></h1>
    <div class="module entry-content">
        <?php the_content(); ?>

        <?php if($pressRelease_posts->have_posts()) { ?>
            <?php while($pressRelease_posts->have_posts()) { $pressRelease_posts->the_post(); ?>

            // custom query looped item

            <?php } ?>
        <?php } ?>
        <?php get_template_part('nav', 'below'); ?>
        <?php wp_reset_postdata(); ?>
    </div>
</article>
<?php endwhile; endif; ?>

另外,每當我嘗試將標簽WP_query添加到此問題時,保存時它不會顯示嗎? 有什么原因嗎?

nav-below.php文件包含:

<div class="bv-pagination marginbottom2 text-center">
    <?php echo paginate_links(array(
        'prev_text' => '<span class="fa fa-fw fa-chevron-left"></span>',
        'next_text' => '<span class="fa fa-fw fa-chevron-right"></span>'
    )); ?>
</div>

在文件中實現此代碼。 這會有所幫助。

<?php

    $args = array( 
        'posts_per_page' => 5, 
        'post_type' => 'post' ,
        'orderby' => 'date',
      'order'   => 'DESC',
      'paged' => ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1
    );

    $postslist = new WP_Query( $args );

?>

<div class="row section blog-posts">

    <?php while ( $postslist->have_posts() ) : $postslist->the_post(); ?>

        <div class="blog-post">

        </div>

    <?php endwhile;  ?>

    <div class="page-controls">
        <?php echo paginate_links( 
                array(
                    'base'               => '%_%',
                    'format'             => '?paged=%#%',
                    'total'              => 1,
                    'current'            => 0,
                    'show_all'           => false,
                    'end_size'           => 1,
                    'mid_size'           => 2,
                    'prev_next'          => true,
                    'prev_text'          => __('« Previous'),
                    'next_text'          => __('Next »'),
                    'type'               => 'plain',
                    'add_args'           => false,
                    'add_fragment'       => '',
                    'before_page_number' => '',
                    'after_page_number'  => ''
                ) 
            );
wp_reset_postdata();
 ?>
    </div>

</div>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM