Forum

Thread tagged as: Question

Blog template that excludes most recent post

Hi Guys,

I have a requirement for a blog post list page where the most recent blog post is large a covers the full-width of the top of the page and then the next 8 most recent sit in two rows of 4 beneath this.

I can achieve the layout using two perch_blog_custom calls and two templates, then by sorting the date and number of returned items. The part i'm stuck on is how to prevent the second perch_blog_custom call also returning the 1st result, it needs to return the 2nd - 9th most recent post.

is this possible?

Chris Bell

Chris Bell 0 points

  • 6 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Set 'start'=>2 on the second instance.

I can't get this to work, this is the code i'm using:

                                perch_blog_custom(array(
                                    'category'   => $cat,
                                    'template'   => $template,
                                    'sort'       => $sort_by,
                                    'sort-order' => $sort_order,
                                    'start'          => 2,
                                ));
Rachel Andrew

Rachel Andrew 394 points
Perch Support

What is happening, or not happening when you say it isn't working? What result do you expect and what are you seeing?

It's still returning the first post, I have two perch_blog_custom calls:

                    perch_blog_custom(array(
                                        'category'   => $cat,
                                        'template'   => $templateSingle,
                                        'count'      => 1,
                     ));

and

                                perch_blog_custom(array(
                                    'category'   => $cat,
                                    'template'   => $template,
                                    'sort'       => $sort_by,
                                    'sort-order' => $sort_order,
                                    'start'          => 2,
                                ));

The first should just show the most recent blog post and the second should show all except the most recent. The reason behind this is the designs for the blog have the most recent blog post much larger than the rest so the best way I know to do this was with two templates

The problem I am seeing here is you sort the second call, and not the first call. Maybe this is changing the output order. ??

Drew McLellan

Drew McLellan 2638 points
Perch Support

You may need to turn pagination off with the paginate option.

Ok So there was a problem with the sort order on the first call, I hadn't noticed but the first call was showing the oldest not the newest so adding the sort order to both has fixed that.

Still having the issue with the second call still showing all the posts and not excluding the first,

Here is the blog page is it's any help: https://calltrain.de22.co.uk/blog/archive.php?cat=blog

Drew McLellan

Drew McLellan 2638 points
Perch Support

What does your code look like now?

Here's the first call:

                    perch_blog_custom(array(
                                        'category'   => $cat,
                                        'template'   => $templateSingle,
                                        'count'      => 1,
                                        'sort'       => $sort_by,
                                        'sort-order' => $sort_order,
                                        'paginate'   => false,
                     ));

and the second

                            perch_blog_custom(array(
                                    'category'   => $cat,
                                    'template'   => $template,
                                    'sort'       => $sort_by,
                                    'sort-order' => $sort_order,
                                    'start'          => 2,

                                ));

When I add paginate to the second it only returns one result and its still the most recent

Drew McLellan

Drew McLellan 2638 points
Perch Support

Try:

perch_blog_custom(array(
    'category'   => $cat,
    'template'   => $template,
    'sort'       => $sort_by,
    'sort-order' => $sort_order,
    'start'      => 2,
    'count'      => 10,
    'paginate'   => false,
));

Great that works!

I've had to set the count to 100 so it shows more than 10 posts but setting the count (along with paginate) made it work, I had tried both things individually but not together

Thanks

Hi,

Sorry to open up old cases, but I don't think this quite answers the bigger picture - what if I want to exclude the first result (with start => 2) AND use pagination?

Do I have to do it manually?

Hi,

Its a little bit of a faff - but it occurred to me I could just get the ID of the first/most recent blog separately, then do an NEQ filter against the postID in my paginated blog_custom function - I'm guessing this is the best way to achieve what I want?

Thanks

If your in need of additional help I suggest you start a new thread as this is a closed thread which will likely go unanswered due to age, and not being the original poster.