We are transitioning over to a new forum platform. Please post new issues there. Existing threads will be dealt with here unless you choose to move them over. Visit the new forum


Thread tagged as: Question, Blog

How to display a blog post's tags as links in the post_in_list.html template

I'm trying to figure out how to display a list of a post's tags that link to the the archive page from within the post_in_list.html template. I am able to show the list of tags with the below template tag:

<perch:blog id="postTags" type="text" />

But I need to have something that works more like what I am able to do inside the post_tag_link.html template:

<a href="archive.php?tag=<perch:blog id="tagSlug" />" rel="tag"><perch:blog id="tagTitle" /></a>

Please let me know what additional context and information you need to better understand my situation. Thank you very much for your time and assistance.

Brent Walter

Brent Walter 0 points

  • 5 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

You need to use the each callback option:

'each' => function($item) {
    $item['tags'] = perch_blog_post_tags($item['postSlug'], 'my_awesome_template.html', true);
    return $item;

And then in your template

<perch:blog id="tags" encode="false" />

Hi Drew,

Thank your for your prompt reply. The solution you shared is exactly what I needed. Just to share with anyone else who might have this issue in the future, here is the full code block I used to achieve the desired result:

        'count' => 10,
        'template' => 'post_in_list.html',
        'sort' => 'postDateTime',
        'sort-order' => 'DESC',
        'each' => function($item) {
            $item['tags'] = perch_blog_post_tags($item['postSlug'], 'post_tag_link.html', true);
            return $item;

That was placed in my blog's index.php file.

Thanks again.