Forum

Thread tagged as: Problem

Show latest blog posts in at bottom of blog by category

Can someone please help me figure out how to show the latest 4 posts at the bottom of a blog post that match that specific post, basically what I want to do is this:

    <perch:if id="catTitle" eq="Blog">
            <?php
            perch_blog_custom(array(
            'count' => 4,
            'template' => 'summary_post_blog_home.html',
            'sort' => 'postDateTime',
            'category' => array('Blog'),
            'sort-order' => 'DESC'
            ));
            ?>
    </perch:if>
    <perch:if id="catTitle" eq="News">
            <?php
            perch_blog_custom(array(
            'count' => 4,
            'template' => 'summary_post_blog_home.html',
            'sort' => 'postDateTime',
            'category' => array('News'),
            'sort-order' => 'DESC'
            ));
            ?>
    </perch:if>

I don't know of any way I can call perch_blog_custom from within the post.html template and not sure how to access the CatTitle attribute from the post.php page.

Can anyone help with this?

Chris Bell

Chris Bell 0 points

  • 6 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Which version of Blog are you running?

Should be the latest version I downloaded it 2 weeks ago

Drew McLellan

Drew McLellan 2638 points
Perch Support

What should happen for posts in multiple categories?

Well they shouldn't be set in multiple, the way I've used categories is a bit of a hack as the client wanted blog and news to be separate and this was the best way I knew to do that,

If a post was set as a news and blog category it would appear in both places so i have to rely on the client not doing that

Hi Drew,

Do you have any update on this?

Drew McLellan

Drew McLellan 2638 points
Perch Support

That what sections are intended for. Anyway, that doesn't really matter.

You need to get the categories for the current post. Normally you'd do that with skip-template but the categories aren't output in that currently (it's a logged bug). Instead, you'll need to use a template that outputs just the category, and then return it to a variable.

Then use that variable to filter the categories for the subsequent calls.

OK so if I have this code in post.php page:

$category = perch_blog_custom(array('template' => 'get_category.html'));

perch_blog_custom(array(
    'count' => 4,
    'template' => 'summary_post_blog_home.html',
    'sort' => 'postDateTime',
    'category' => array($category),
    'sort-order' => 'DESC'
));

I'm not sure how in my get_category.html template I would turn a perch tag into a returned value and ensure that it's the same category as the post being viewed.

Will look at using sections on my next Perch site but too far down the road with this one (This is the last page).

Drew McLellan

Drew McLellan 2638 points
Perch Support

Like this:

<perch:categories id="your_cat_id"><perch:category id="catPath" /></perch:categories>

I have this code now:

<perch:categories id="categories"><perch:category id="catSlug" /> <br></perch:categories>

This now outputs the category for each blog post in the database but can't figure out how to filter that by current category/post ?

Drew McLellan

Drew McLellan 2638 points
Perch Support

It may be easier to wait for the skip-template fix that should be out today or tomorrow.

Ok, I can have both News and Blog outputted to the page and use jQuery to show the correct set of results as a temporary fix.

Drew McLellan

Drew McLellan 2638 points
Perch Support

That fix should now be in Perch 2.7.6.