Forum

Thread tagged as: Question, Addons, Blog

Load more blog posts

I'm displaying the three most recent blog posts on my blog index page using perch_blog_recent_posts(3);

I'd like to add a "Load More" button beneath, which when clicked, will display the previous three blog posts in descending order from the last post that was displayed.

I've tried to follow the solution marked here, but I'm having a tough time adapting and filtering to the blog.

Any help would be greatly appreciated!

Olympia Kyriakides

Olympia Kyriakides 1 points

  • 6 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Ok, what code do you have and how is it failing for you?

Hi Drew, I kept at it and this seems to be working. I used 'start' but hoping it's not just a hack!

One thing still outstanding: when I "Load More" the page reloads to the very top of the page. I'd like for it to load at the top of the new content. Because its coming in dynamically, I'm not sure where on the page (or in the template) to id/link the scrolling. Would some sort of 'if' statement be a better approach? Do you have any advice on this? Thank you again!

<?php perch_blog_recent_posts(3);?>

<?php

        $increment = 3;
        $count = (int) perch_get('count', $increment);

        perch_blog_custom(array(
            'paginate' => false,
            'count'=>$count,
            'template'=>'post_in_list.html',
            'sort'=>'postDateTime',
                        'sort-order'=>'DESC',
            'start'=>4,

        ));

        echo '<a href="?count='.($count+$increment).'">Load more</a>';
        ?>
Drew McLellan

Drew McLellan 2638 points
Perch Support

I guess you'd need to put the ID in the template somewhere before the last 3 items.

I can't think of a good way to do that.