Forum

Thread tagged as: Question, Problem, Blog

Next/Prev buttons still not working correctly

Sorry I thought it was working so I marked my previous thread as solved but it's still not working.

I have 4 test blog pages but on every post the next and previous links are linking to the 2nd and 4th page. I'm assuming there is something wrong with the first part that checks for what post its on but I can't figure it out.

<?php 

$result = perch_blog_custom(array(
    'sort'=>'postDateTime',
    'section' => 'comic-pages',
    'sort-order'=>'ASC',
    'value' => $result[0]['postDateTime'],
    'template'=>'blog/post_comic_page_prev.html',
    'count'=>1,
    'skip-template' => true,
    'return-html'   => true,
    )); 

PerchSystem::set_var('is_prev', true);

perch_blog_custom(array(
    'template'   => 'blog/post_comic_page_prev.html',
    'filter'     => 'postDateTime',
    'section'   => 'comic-pages',
    'match'      => 'gt',
    'value'      => $result[0]['postDateTime'],
    'sort'       => 'postDateTime',
    'sort-order' => 'ASC',
    'count'      => 1,
    ));

echo $result['html'];

?>

<?php 

$result = perch_blog_custom(array(
    'sort'=>'postDateTime',
    'section' => 'comic-pages',
    'sort-order'=>'DESC',
    'value' => $result[0]['postDateTime'],
    'template'=>'blog/post_comic_page_next.html',
    'count'=>1,
    'skip-template' => true,
    'return-html'   => true,
    ));

PerchSystem::set_var('is_next', true);

perch_blog_custom(array(
    'template'   => 'blog/post_comic_page_next.html',
    'filter'     => 'postDateTime',
    'section'   => 'comic-pages',
    'match'      => 'lt',
    'value'      => $result[0]['postDateTime'],
    'sort'       => 'postDateTime',
    'sort-order' => 'DESC',
    'count'      => 1,
    ));

echo $result['html'];

?>
Jana Hoffmann

Jana Hoffmann 0 points

  • 6 years ago

Hi Jana, I am not sure this is possible in the blog. I think this functionality might be only possible on list and details pages.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Get the current post and store it in $result:

$result = perch_blog_custom(array(
    'section' => 'comic-pages',
    'filter' => 'postSlug',
    'match' => 'eq',
    'value' => perch_get('s'),
    'skip-template' => true,
    'return-html'   => true,
    )); 

To show the post:

echo $result['html'];

To show the previous link (the date of the post is less than the date of the current post):

PerchSystem::set_var('is_prev', true);

perch_blog_custom(array(
    'template'   => 'blog/post_comic_page_prev.html',
    'section'   => 'comic-pages',
    'filter'     => 'postDateTime',
    'match'      => 'lt',
    'value'      => $result[0]['postDateTime'],
    'sort'       => 'postDateTime',
    'sort-order' => 'DESC',
    'count'      => 1,
    ));

To show the next link (the date of the post is greater than the date of the current post):

PerchSystem::set_var('is_next', true);
perch_blog_custom(array(
    'template'   => 'blog/post_comic_page_next.html',
    'section'   => 'comic-pages',
    'filter'     => 'postDateTime',
    'match'      => 'gt',
    'value'      => $result[0]['postDateTime'],
    'sort'       => 'postDateTime',
    'sort-order' => 'ASC',
    'count'      => 1,
    ));

Yay I got there. Thanks so much for your patience and assistance