Forum
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!
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.
You can't preset a template for the section, only post-by-post or for each blog.
And how do you preset a template post-by-post or for each blog?
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
Be sure to add the
section
option to your code to filter only by that one section.