Forum
Issue with previous link for blog posts
Is anyone else getting an issue with the previous link on their blogs where it links to the current post and not the previous one? The next link works absolutely fine but I cannot see what's up with previous link.
I have Perch 2.8.7, the is Blog App 4.6 and PHP is 5.6.7.
The HTML templates for $next
and $prev
just contain an <a>
for the links.
<?php
$result = perch_blog_custom(array(
'filter' => 'postSlug',
'match' => 'eq',
'value' => perch_get('s'),
'skip-template' => true,
'return-html' => true,
));
$next = perch_blog_custom(array(
'template' => 'blog/post_next.html',
'filter' => 'postDateTime',
'match' => 'gt',
'value' => $result[0]['postDateTime'],
'sort' => 'postDateTime',
'sort-order' => 'ASC',
'count' => 1,
'skip-template' => true,
'return-html' => true,
));
$prev = perch_blog_custom(array(
'template' => 'blog/post_prev.html',
'filter' => 'postDateTime',
'match' => 'lt',
'value' => $result[0]['postDateTime'],
'sort' => 'postDateTime',
'sort-order' => 'DESC',
'count' => 1,
'skip-template' => true,
'return-html' => true,
));
echo $result['html'];
?>
<div>
<h3>What to read next</h3>
<nav>
<?php
echo $next['html'];
echo $prev['html'];
?>
</nav>
</div>
That looks fine. What does debug output?
For context there are three articles: one, two and three. Article three is the newest and article one is the oldest:
Article one published 17 May 2015
The debug below is from article two. The result I get is the next post is article three (correct), but the previous post is article two when it should be article one.
That really looks like it should work.
If you run the queries directly, do you get sane results back?