如何添加博客下一个上一个导航


How do add the blog next prev navigation?

我对我的日记文章使用自定义文章类型,但我想为上一页和下一页添加导航。因此,如果我的期刊页面上有超过 5 篇文章,我将分页下一个链接或数字 2、3、4 等......如果没有更多的帖子,它应该显示上一个。现在,我的期刊页面在索引上.php .

在我的WordPress阅读设置中,我使用静态页面来显示我的首页。我的首页是首页.php我的帖子页是期刊页。博客页面最多显示 5 篇文章。联合提要显示最近的 5 个帖子。

如何使用我的自定义帖子类型"日记"添加下一个和上一个导航?

<?php 
    get_header();
    ?> 
    <!-- journal -->
    <section class="container-wrap">
        <?php
            $args  = array('post_type' => 'journals');
            $query = new WP_Query($args);
            while($query -> have_posts()) : $query -> the_post();
        ?>
        <article class="post-wrap">
            <header>
                <a href="<?php the_permalink(); ?>" class="post-title">
                    <h1 class="post-title"><?php the_title(); ?></h1>
                </a>
                <span class="post-date"><?php echo(types_render_field('date', array('format' => 'm.d.Y') )); ?></span>
            </header>
        </article>
        <?php endwhile; ?>
        <?php wp_reset_query(); ?>
    </section>
    <!-- /journal -->
    <?php 
    get_footer();
    ?>

paginate_links 钩子与自定义WP_Query数组结合使用。请确保为查询指定paged数组参数。这会设置查询以返回分页结果。

  <?php
    // 1- Setup paging parameter
    $paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
    // 2- Setup WP_query variable to get last 12 posts
    $args = array(
      'posts_per_page' => 12,
      'post_type' => 'journals',
      'orderby' => 'most_recent',
      'paged' => $paged,
    );
    $the_query = new WP_Query( $args );
    // 3- Setup new loop
    if($the_query->have_posts()) : 
      while($the_query->have_posts()) : 
        $the_query->the_post();
    // 4- Output parameters you want here
        echo '<div class="col-md-4">';
        echo '<h4><a href="' . the_permalink() . 'title="Read more">' . the_title() . '</a></h4>';
        echo '<a href="' . the_permalink() . '">' . the_post_thumbnail() . '</a>';
        echo the_excerpt();
        echo '</div>';
    // 5- close up loop
      endwhile;
    endif;
    // 6- Output paginate_links just below post loop
    echo paginate_links( array(
      'base' => str_replace( 999999, '%#%', esc_url( get_pagenum_link( 999999 ) ) ),
      'format' => '?paged=%#%',
      'current' => max( 1, get_query_var('paged') ),
      'total' => $the_query->max_num_pages
    ) );
    // 7- reset post data query
    wp_reset_postdata(); 
  ?>

试试这个我的代码,它在我的网站上工作 http://www.thehiddenwhy.com/blog/请此链接 如何在WordPress的页面代码中创建分页?