Forum

Thread tagged as: Question, Addons, Blog

IF statements on post.php page in Blog add-on

Hello,

I have created a Blog using the Blog Add-on. I also have two sections ('News' & 'Case Studies').

I've created two separate templates for each section which lists the appropriate blog articles within that section. However the blog post page itself is located on the same URL for each section as there's only one option in Perch Settings ('/perch/core/settings/').

I'd like my blog post page path to be '/news/post?s={postSlug}') for News and '/case-studies/post?s={postSlug}' for Case Studies - at the moment it's just one URL for both. Is this possible?

If it's definitely not, I will settle for one blog post page path for both, however I'd like to use IF statements on the 'post.php' template.

For example:

<perch:if section="case-studies">You're on Case Studies<perch:else>You're on News</perch:if>

Please let me know how to do this.

Thank you in advance!

Elliott Mangham

Elliott Mangham 0 points

  • 5 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

I think you can use {sectionSlug} in the blog post path in Settings - did you try that?

Drew McLellan said:

I think you can use {sectionSlug} in the blog post path in Settings - did you try that?

Thanks Drew that worked perfectly. Each section now has it's own unique path.

Is it also possible to use a different HTML template for the blog post too? It's the file in '/addons/apps/perch_blog/templates/blog/post.html'.

Can I use a different one for each section as the post content itself varies slightly?

Thank you.

Drew McLellan

Drew McLellan 2638 points
Perch Support

You can't preset a template for the section, only post-by-post or for each blog.

Drew McLellan said:

You can't preset a template for the section, only post-by-post or for each blog. So is there any way of using IF conditions in the 'post.html' to detect what section it's in?

And how do you preset a template post-by-post or for each blog?

Drew McLellan

Drew McLellan 2638 points
Perch Support

Under Blog > Blogs, click through to edit each blog and set the "Default master template" option.

Thank you but I can't find that option on the blogs. For now for a temporary solution I've set it up with a checkbox, so IF you check that it adds the code I needed.

The remaining issue is that the Next/Previous buttons are linked between Case Studies and News. Meaning if you're on the latest blog post which is a Case Study and you click on "Previous", it will take you to the previous post even if it's a News post.

I used this code for Next/Previous buttons: https://forum.grabaperch.com/forum/03-08-2015-generating-links-to-the-previous-and-next-blog-post

Drew McLellan

Drew McLellan 2638 points
Perch Support

Be sure to add the section option to your code to filter only by that one section.

Drew McLellan said:

Be sure to add the section option to your code to filter only by that one section. That worked a dream. Thanks Drew.