Forum
Latest/Most Recent post
Hi,
I'm looking to find out if anyone knows of a better way to achieve the following -
I want to make the latest (most recent) post stand out (styled differently) from the main blog listing on the blog page of a site.
Currently I've set this up by including a checkbox within the post template, so that a post can be marked "featured". On the blog list page, I'm then using "'match'=>'eq'" and "'match'=>'neq'" to pull the posts into the list/s:
Featured post list (one item only) -
<?php
perch_blog_custom(array(
'filter'=>'featured_post',
'match'=>'eq',
'value'=>'featured',
'sort'=>'postDateTime',
'sort-order'=>'DESC',
'template'=>'blog/feature_post.html',
'count'=>1,
));
?>
Remaining posts list -
<?php
perch_blog_custom(array(
'filter'=>'featured_post',
'match'=>'neq',
'value'=>'featured',
'sort'=>'postDateTime',
'sort-order'=>'DESC',
'template'=>'post_in_list.html',
'count'=>10,
'paginate'=>true,
'page-links'=>true,
));
?>
This works, but requires the user to update the featured checkbox each time a new post is added so that previously featured post is unchecked and the new post checked as featured.
Is there an easier option for doing this without a checkbox that I'm completely missing? I only ever need the Latest post, so not necessarily a featured post from the distant past. I also need paging so can't use a start count to display the remaining post list like below -
Featured post list (one item only) -
<?php
perch_blog_custom(array(
'sort'=>'postDateTime',
'sort-order'=>'DESC',
'template'=>'blog/feature_post.html',
'count'=>1,
));
?>
Remaining posts list -
<?php
perch_blog_custom(array(
'sort'=>'postDateTime',
'sort-order'=>'DESC',
'template'=>'post_in_list.html',
'count'=>10,
'start'=>2,
'paginate'=>true,
'page-links'=>true,
));
?>
Thanks!
If you're setting the
start
value, you need to turn off the pagination - you can't both control the paging yourself and have Perch do it - it's one or the other.A simpler route would be to branch in the template. If it's page 1 and the first item, then do this, else do that.
Thanks for the quick reply Drew.
Is there an example of how a perch "If" statement would detect "If it's the first page and first item"?
What would I need to use for #attribute# / #page-1# / #first-item# values?
Thanks again for the help!
I think you might be getting template languages mixed up. You should be able to do something like:
Cheers Drew, this makes much more sense now.
I just wasn't sure what attribute values I needed to include within the "If statement" to detect the "page number" and "first item"
Apologies for my dodgy #attribute# additions, couldn't think of a better way to explain which attribute/values that I wanted!
I will test this out, thanks again!