Forum

Thread tagged as: Blog

Perch Blog - Category Links to Section's Category only

I have three separate news feeds on a site I am building. i.e.:

They share categories types. General, Events, Help & Advice.

The Archive list on the side is working fine by only showing a count for the articles within that section. However when clicking on the Archive links to filter the articles it is showing all the articles from the other Sections also. So even though the count may be "General (3)" the resulting pages shows '6' articles because it's including the artless from other sections.

This is the link in the template:

<li><a href="archive.php?cat=<perch:blog id="categorySlug" />"><perch:blog id="categoryTitle" /> (<perch:blog id="qty" />)</a></li>
<perch:after></ul></li></ul></perch:after>

What would I need to change to make it only show the (3) articles from that section in the resulting page?

James Tedder

James Tedder 0 points

  • 7 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

You need to pass the section slug through to your archive page, and then filter based on section.

Ok... any documentation on this? I wouldn't know where to start.

Drew McLellan

Drew McLellan 2638 points
Perch Support

To filter any of the blog functions by section add:

'section' => 'my-section-slug'

to the options. If that slug is on the URL as section=my-section-slug you could use

'section' => perch_get('section')

The archive categories links are showing the correct amount of articles on the side. My issue is the side Archive link to the filtered Categories which needs to change?

Clicking the "General News (3)" link takes me to a page showing (5) articles because it's including the posts from other 'Sections' tags with the "General News" category.

This is the URL it shows:

/teachers/news/archive.php?cat=general-news

Drew McLellan

Drew McLellan 2638 points
Perch Support

Yes, you'll need to pass the section slug in the link and then add a filter for the section on any listing you output.

I think it may be because I am not using section.php in my site? I have 3 directories for the three sections each with their own, index,archive, and post pages as follows:

Teachers - index.php - post.php - archive.php

Students - index.php - post.php - archive.php

Parents - index.php - post.php - archive.php

Each index.php filters the posts with:

<?php
        perch_blog_custom(array(
        'sort' => 'postDateTime',
        'sort-order' => 'DESC',
        'section' => 'section-name',
        'count' => 10,
        'template' => 'post_in_list.html'
        ));
      ?>

And the Archive List is filtering with:

<div class="sideModule">
     <!--  By category listing -->
      <?php
      perch_blog_categories(array(
      'section' => 'section-name',
      ));
      ?>
    </div><!-- sideModule -->
    <div class="sideModule">
      <!--  By year -->
      <?php perch_blog_date_archive_years(array(
      'section' => 'section-name',
      ));
      ?>
    </div><!-- sideModule -->

How would I "pass the section slug in the link"

Drew McLellan

Drew McLellan 2638 points
Perch Support

perch_blog_categories and perch_blog_date_archive_years both use templates that contain links.

Pass in the section slug:

PerchSystem::set_var('sectionSlug', 'section-name');

and then use it in the links in those templates:

<perch:blog id="sectionSlug" />