Forum

Thread tagged as: Question, Runway, Blog

Minimum number of items before displaying

Hi, me again!

Using perch_blog_custom() is there a way of setting a minimum number of blog posts before the posts will display?

So for example, I've got staff profile pages that display the blog articles that have been written by them but I want to set a minimum number so that the row of posts only show if there are 4 posts or more.

I hope that makes sense?

Many thanks

Glen Piggott

Glen Piggott 0 points

  • 1 week ago
Drew McLellan

Drew McLellan 2550 points
Perch Support

Yes, use both skip-template and return-html. If the number of items returned in more than 4, then echo the HTML value.

Thanks Drew.

I've now got the following but nothing is displaying / outputting.

    perch_blog_custom([
        'sort' => 'postDateTime',
        'sort-order' => DESC,
        'count' => 4,
        'template' => 'profile_posts.html',
        'filter' => 'author.profileSlug',
        'match' => 'eq',
        'value' => perch_get('profileSlug'),
        'skip-template' => true,
        'return-html' => true,
    ]);

...I've never worked with skip-template or return-html before so how would I echo the html when there are 4 or more posts please?

Thank you

Hi Glen,

You would need to do something like this

$posts = perch_blog_custom([ 
'sort' => 'postDateTime',
'sort-order' => DESC,
'count' => 20, 
'template' => 'profile_posts.html',
'filter' => 'author.profileSlug',
'match' => 'eq',
'value' => perch_get('profileSlug'),
'skip-template' => true,
'return-html' => true, 
], true);

if(PerchUtill::count > 3) {
echo $posts['html'];
}

Thank you Dexter.

I've now got the following but all html / content on the page from this point onwards now stops. Eg the footer is now not showing.

    $posts = perch_blog_custom([
        'sort' => 'postDateTime',
        'sort-order' => DESC,
        'count' => 4,
        'template' => 'profile_posts.html',
        'filter' => 'author.profileSlug',
        'match' => 'eq',
        'value' => perch_get('profileSlug'),
        'skip-template' => true,
        'return-html' => true,
    ], true);
    if (PerchUtill::count > 3) {
        echo $posts['html'];
    }

...knowing me it's probably something really simple and obvious

Hello Glen,

I think it should be PerchUtil::count($posts) > 3, otherwise Dexter's solution is spot on.

That's it

Thank you, everyone - great teamwork!

Glen

Yes sorry, typo on my part