Forum

Thread tagged as: Question

Filter by marked archived years.

Hi,

I have been working on filtering the news list based on years, it worked fine for me. But now I need to add another feature which is to mark any number of years as Archived and then when in my website UI, the user will click on "Archieve" it should show all the news in sorted order for all the years which where marked as Archive by the admin user.

For example: I have news for each of the years: 2010 to 2016 but now I mark years 2010-2012 as archived news. So when I would need to see all the achieved years news, I would click on Archive ad should be able to see them all.

Could you please help me with a way out of it?

Damian McCracken

Damian McCracken 0 points

  • 4 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

How are you planning on marking those years?

I have given a checkbox with label "Archive" in the perch control panel, which is when checked of number of years will consider all these as archived news years.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Ok, so on your archive page, you'll need to fetch those values and then use them in your filter to get the news list.

Exactly this is what I want to do. Thanks for understanding Drew.

How can I do that, also the news should show up in sorted order (by date).

Drew McLellan

Drew McLellan 2638 points
Perch Support

Which part are you struggling with? Have you fetched your archived years?

No, I will try explaining my concern again. When I mark a few years as Archive, it gets hidden from the filter pane (which is correct), now when I click on "Archive" option from the filter pane it should show news of all those years which were marked archive. This is what I need help with?

To elaborate on the issue, there are 2 different pages: 1. Perch control panel page; which has that archive check box. 2. PHP page where my news lists show up along with the filtering option.

Is there any way I can manage to link these 2 page code/items?

Hope this make sense to you now.

My code for perch control panel check box & filter item is as below:

<div id="ArchiveDiv">
    <perch:repeater id="News-year" label="News filter">

    <perch:content type="checkbox" id="News-year" label="Show in archive" suppress="true" />

    <perch:if exists="News-year" id="archiveYear" >

        <li>       
            <a class="sidebar-brand" onClick="GetYearNews(this)" >
                <span class="">
                    <perch:content id="allnews-year" type="text" label="Filter news by year" />
                </span> 
            </a>
        </li>

    </perch:if>

    </perch:repeater>

    <li>
        <a class="sidebar-brand" onClick="GetAllArchiveYearNews()" >  <span class="">
            Archive
        </a>
    </li>

    <div>
        </ul>
    </div>

</div>

My code on php News webpage is as below: 'News_master_page.php' this page is not getting called in the below, don't know why it is so.

<?php
perch_content_custom('News page', [ 
'page'=>'News_master_page.php', 
'template'=>'News_page.html',
'filter'=>'event_date',
'match' => 'eqbetween',
'sort' => 'event_date',
 'sort-order' => 'DESC',
]);
?>
Drew McLellan

Drew McLellan 2638 points
Perch Support

I understand what you're trying to do. I've explained the steps, which you seem to agree with. What I don't understand is why you're not then doing that. Where are you stuck?

Have you got your list of archive years back? If not, where's the problem?

I'm not sure what this is or how it relates, but:

perch_content_custom('News page', [ 
 'page'=>'News_master_page.php',  
'template'=>'News_page.html', 
'filter'=>'event_date', 
'match' => 'eqbetween', 
'sort' => 'event_date', 
'sort-order' => 'DESC', 
]);

The page option needs to be root-relative, so starting with a /.

You're setting filter and match but not value, so there's nothing to filter on.