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.
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();
?>
Use the
paginate_links
hook in combination with a customWP_Query
array. Make sure to specify thepaged
array parameter for the query. This sets up the query to give back paged results.Try this my code it’s working on my site http://www.thehiddenwhy.com/blog/ please this link How to create pagination in page code in wordpress?