Forum

Thread tagged as: Blog

Show related blog posts with the same tag

My client would like their blog to display related articles under each blog post. All their posts are tagged. Is there a way to display posts that share the same tag below an article, say with the post title and image?

Thanks!

Franz Neumann

Franz Neumann 0 points

  • 3 years ago
Drew McLellan

Drew McLellan 2636 points
Perch Support

You can use perch_blog_custom() to filter by the postTags field where it contains another tag.

Ah, that would work. What would I put in for value, however?

<?php perch_blog_custom(array( 'filter' => 'postTags', 'match' => 'contains', 'value' => '', )); ?>

Thanks!

Drew McLellan

Drew McLellan 2636 points
Perch Support

Any of the tags you want to match against - so the tags from the current post.

Drew,

Not sure I follow. I don't know what a particular blog entry is tagged as--that's up to my client when they submit a new entry. The above solution needs a way of displaying only those blog entries that share the same tag. But I'm not sure how I express that condition in the code since the perch_blog_custom function needs to work with any tag my client chooses to use. I hope that makes sense.

Drew McLellan

Drew McLellan 2636 points
Perch Support

You can use perch_blog_custom() with the skip-template option to get the tags for the current post.

Solved.