Forum

Thread tagged as: Question, Configuration, Blog

Display/hide option for blog in list

Hello

On my homepage I have this function to display 3 of the latest news (blog) posts on my homepage.

<?php
perch_blog_custom(array(
    'filter' => 'postDateTime',
   'count' => '3',
    'template' => 'homepage_post_in_list.html',
));
?>

I wanted to add a perch:if and checkbox to turn this feature on and off as the client wishes. How would I do this? I tough I could create a template with my checkbox sand a code box (like below) but this does not work because I guess it only allows html not php

<perch:content type="checkbox" id="news" value="1" label="Display News / Blog" suppress="true" />
<perch:if exists="news"><div><h3>Latest News</h3>
<perch:content id="text" type="textarea" label="Code" html="true" editor="markitup" />
</div>
</perch:if>
Denise Courtney

Denise Courtney 0 points

  • 5 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

The simplest way (and probably most logical) would be to use a page attribute.

https://docs.grabaperch.com/functions/page-attributes/perch-page-attribute/

if (perch_page_attribute('blog_on_home', [], true)) {
    perch_blog_custom(array( 'filter' => 'postDateTime', 'count' => '3', 'template' => 'homepage_post_in_list.html', ));
}

Hi drew

I cant seem to get this working of fathom out how too.

So the 'if' code is my php page function, yes? So would I have a checkbox template in my content to turmn the function on and off?

Drew McLellan

Drew McLellan 2638 points
Perch Support

You'd add a page attribute to control it.