2017-05-04, 03:49:06
(2017-04-29, 17:18:39)joyofweaving.com Wrote: Thank you for such a fabulous plug-in. I love using it. The individual posts have a "back" link to previous posts. How do I add a link to "next" when there are more posts after it?
I'll eventually add the previous/next posts feature - it's still in the to-do list (#6)
In the meantime you can use this snippet:
PHP Code:
<?php
if (nm_is_single()) {
$posts = nm_get_posts();
$current = nm_post_slug(false);
$count = 0;
foreach ($posts as $post) {
if ($post->slug == $current) break;
$count++;
}
$next = $count >= 1 ? $posts[$count-1] : false;
$prev = $count < count($posts) ? $posts[$count+1] : false;
?>
<div class="nm_prev_next">
<?php if ($prev) { ?>
<div class="nm_previous_post"><a href="<?php echo nm_get_url('post'),$prev->slug; ?>" title="<?php echo $prev->title; ?>">Previous post</a></div>
<?php } ?>
<?php if ($next) { ?>
<div class="nm_next_post"><a href="<?php echo nm_get_url('post'),$next->slug; ?>" title="<?php echo $next->title; ?>">Next post</a></div>
<?php } ?>
</div>
<?php
}
?>
You can paste it in your template, or create a component (e.g. nm-prev-next) and then enable NM Custom Settings and enter this:
Code:
single componentBottomPost nm-prev-next
componentAfterPost
instead if you want to have the links under the "go back" link)You can style the links using classes .nm_previous_post, .nm_text_post, etc. (or if you use a Bootstrap-based template you may prefer to change all those <div>'s to <ul class="pager"> and <li>'s)