Forum

Thread tagged as: Question, Blog

Linking directly to the latest post of a specific category?

Hi Drew,

Is it possible to pull into a page the latest blog post of a specific category? I'd like to have a link in the main navigation to a 'Designer of the Month' (which would be a blog post) that displays the 'full' post of most recent designer (i.e. no listing). I have a 'Designer of the Month' category setup in the blog app. Any pointers as to how I might do this.

Regards - Nick

Nick Loat

Nick Loat 0 points

  • 6 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Yes, filter by category, order by date in descending order and take just one result.

Hi Drew,

Got this working following your advice, however how do I pull in the associated comments and add a comments form? (not sure how I pull in the correct id)

Drew McLellan

Drew McLellan 2638 points
Perch Support

Both of those functions take either a postID or a postSlug to find the matching post. What does your code look like?

I'm using to get the post…

<?php 
            perch_blog_custom(array(
    'count' => 1,
    'sort' => 'postDateTime',
    'sort-order' => 'DESC',
    'category' => array('designer-of-the-month'),
    'template' => 'post.html',
));
    ?>

and then

<?php perch_blog_post_comments(perch_get('s')); ?>
<?php 
perch_blog_post_comment_form(perch_get('s'), array(
    'template' => 'comment_form.html',
)); 
?>

to get the comments and the form. However neither show up. I think its because the slug isn't being appended to the url

Drew McLellan

Drew McLellan 2638 points
Perch Support

Try:

$post = perch_blog_custom(array(
    'count' => 1,
    'sort' => 'postDateTime',
    'sort-order' => 'DESC',
    'category' => array('designer-of-the-month'),
    'template' => 'post.html',
    'skip-template' => true,
    'return-html' => true,
));

echo $post['html'];

and then

perch_blog_post_comments($post[0]['postID']);

…like a dream, many thanks Drew.