Forum

Thread tagged as: Question, Docs, Blog

Filtering perch blog categories

Hi

you have a document on perch_blog_categories which says that you can toggle which categories you show on your site by adding a textbox to the category.html file.

Since you have move to a global category sets, this artilcle is no loner working.

the article says - <perch:blog id="visible" type="checkbox" value="1" label="Show on site" />

but this does not show in the blog categories, you need to add <perch:category id="visible" type="checkbox" value="1" label="Show on site" />

but when you try and filter by

<?php
    perch_blog_categories(array(
        'template' => 'category_link.html',
        'filter' => 'visible',
        'match' => 'eq',
        'value' => '1',
    ));
?>

you get no categories at all.

How do i not show 1 category with perch_blog_categories

Regards,

Brett

Brett Warne

Brett Warne 0 points

  • 6 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Categories can't current be filtered that way. I didn't anticipate categories being used like that, so I'll need to switch them to use an index so they can be filtered.

Hi Drew

I will explain why. A few of my customers always want 1 news item to always be at the top of the list, i am sure there are a lot of way to do this but i normally use a category of "pin to top" and then use

 <?php 
        perch_blog_custom(array(
      'category' => 'pin-to-top',
        'sort'=>'postDateTime',
        'sort-order'=>'DESC',
        'start'=>1,
        'count'=>1,
        'template'=>'post_in_list_news_listing.html',
    ));

?>

 <?php 
        perch_blog_custom(array(
      'category' => 'latest-news',

        'sort'=>'postDateTime',
        'sort-order'=>'DESC',
        'start'=>1,
        'count'=>9,
        'template'=>'post_in_list_news_listing.html',
    ));

?>


so you always have the item you want at the top of the list.

The issue is when you use

perch_blog_categories();

you see the category - pin to top with a count of 1.

If there is an easier way of hiding a category can you let me know.

Regards,

Brett

Drew McLellan

Drew McLellan 2638 points
Perch Support

I don't see a reason we can't implement this - I've logged it to look into.

Hi Drew

my site is live now so do you know when you may implement this?

Regards,

Brett

Drew McLellan

Drew McLellan 2638 points
Perch Support

Yes, probably in Perch 2.9.

Thanks

Hi Drew

With the release of Blog 5.0 this question is probally redundant, now you can create a pin to top blog and use it to display the blog you want first.

and with being able to only output the categories of the main blog it has solved my issue.

  <?php 
        perch_blog_custom(array(
         'count'      => 1,
      'sort'       => 'postDateTime',
      'sort-order' => 'DESC',
      'blog'       => 'pin-to-top',
        'template'=>'post_in_list_news_listing.html',
    ));

?>

 <?php 
        perch_blog_custom(array(
      'category' => array('latest-news',),

        'sort'=>'postDateTime',
        'sort-order'=>'DESC',
        'start'=>1,
        'count'=>9,
        'template'=>'post_in_list_news_listing.html',
    ));

?>

and then only output the categories of the main blog.

perch_blog_categories(array(
      'blog' => 'blog',
      ));

Great update, well done...

Drew McLellan

Drew McLellan 2638 points
Perch Support

Great stuff.