How do add the blog next prev navigation?

I use custom post type for my journal post but I want to add navigation for previous and next page. So If I have more than 5 post on my journal page, I will page next link or the number 2,3,4, etc… If there is no more post, it should display previous. Right now, my journal page in on the index.php .

And in my wordpress reading settings, I use a static page for my front page displays. My front page is front-page.php and my posts page is journal page. Blog pages show at most 5 posts. Syndication feeds show the most recent 5posts.

Read More

How do I add next and previous navigation using my custom post type “journals”?

<?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();

    ?>

Related posts

2 comments

  1. Use the paginate_links hook in combination with a custom WP_Query array. Make sure to specify the paged array parameter for the query. This sets up the query to give back paged results.

      <?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(); 
      ?>
    

Comments are closed.