Forum

Thread tagged as: Blog

perch_blog_post with paginated listing on same page

Hello Perch,

I've got a blog in development which shows the most recent post by default until the user selects a particular one, as well as a paginated list of all posts alongside. (HTML removed for clarity's sake)

perch_blog_custom(array(
    'template' => 'listing.html',
    'sort' => 'postDateTime',
    'sort-order' => 'DESC',
    'count' => 2
));

if(isset($_GET['postID'])) {
    perch_blog_post(perch_get('postID'));
} else {
    perch_blog_custom(array(            
'count' => 1,
        'sort' => 'postDateTime',
        'sort-order' => 'DESC',
        'paginate' => false
    ));

};

The problem is, when the URL contains a page variable for the pagination AND a postID variable for a selected post, the

perch_blog_post(perch_get('postID'))

function no longer returns any data, despite being able to correctly echo out the postID var.

I'm a little lost as to how the page var affects the rendering of the selected post though...

As always guys, many thanks in advance for any pointers!

All the best,

Liam

Liam Coates

Liam Coates 0 points

  • 6 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

I think perch_blog_post() just passes through to perch_blog_custom() under the hood, so the pagination will affect it to. You should replace it with:

perch_blog_custom([
    '_id' => perch_get('postID'),
   'paginate' => false,
]);

Hi Drew, thanks for the reply!

I'll give this a go when I can and let you know - I've currently got a far more pressing issue which I need to post about across the other side of the forum :)

Cheers,

Liam

Hello Drew,

Sorry for the delayed reply here. This sadly doesn't appear to have done the trick - this actually seems to prevent Perch finding the requested post at all, regardless of the page variable.

Liam

Drew McLellan

Drew McLellan 2638 points
Perch Support

Can you show me the options that aren't working?