Problems, need help? Have a tip or advice? Post it here.
7 posts Page 1 of 1
Hi,
Can anyone point me in the right direction on how to filter list of pages by Folder and Archive date at the same time? I have searched the whole forum but can't seem to find what I want.

I want to have to drop downs: One will have a list of the folders and the other will have the list of dates for projects. If a user selects any of the folders, a list of projects under the particular folder will show. The user can also use the drop-down of archive dates to filter the pages under the current folder. Any help will be greatly appreciated.
Hi,

Could you please clarify whether you need this for the admin-panel or the front-end?
Hi KK,
I need this for Front-End. Thank you
That should be straightforward - use the 'start_on' and 'stop_before' parameters of <cms:pages> to specify the time period for the fetched pages and the 'folder' parameter to specify the folder. e.g. -
Code: Select all
<cms:pages 
    folder=k_folder_name
    start_on=my_start_date
    stop_before=my_stop_date
    >   

The code above assumes the 'my_start_date' and 'my_stop_date' variables have been supplied by your filter (e.g. dropdown values passed through URL querystring). Please remember that the dates need to be only in 'yyyy-mm-dd' format e.g. '2018-09-30'. Setting a blank value will make <cms:pages> ignore that parameter.

If you need help with creating such a form, you may use viewtopic.php?f=8&t=7620 as an example (unlike the mentioned post, you don't have to collect all URL parameters into a single string for 'custom_field' so your use-case should be easier to code).

Hope this helps.
Hi KK I did this for the form:
Code: Select all
<cms:form name="quicksearch" id="quicksearch" anchor='0'>
      
      <div>
         <label>Locality</label>
         <cms:input type="dropdown"
               opt_values='Filter by Client=- | <cms:folders masterpage="project.php"><cms:show k_folder_name /><cms:if k_paginate_bottom> | </cms:if></cms:folders>'
               opt_selected='-'
               name="project_client" />
      </div>
      <div>
         <label>Property Type</label>
         <cms:input type="dropdown"
               opt_values='Filter by date=- | <cms:archives masterpage="project.php"><cms:date k_archive_date format='Y' /><cms:if k_paginate_bottom> | </cms:if></cms:archives>'
               opt_selected='No Preference'
               name="property_type" />
      </div>
      <div class="buttonset">
         <cms:input type="submit" class="fbsubmitbtn" value="Start Searching!" name="submit"/>
      </div>
   </cms:form>


and this for the pages tag:
Code: Select all
<cms:if k_is_list>
<cms:pages masterpage="project.php" paginate='1' limit='9' folder=k_folder_name start_on=k_archive_date stop_before=k_next_archive_date>
......
<cms:no_results>
No projects found
</cms:no_results>
</cms:pages>
</cms:if>


But it seems not to be working
I can see two problems with your code -
1. You are using 'single quotes' while trying to set 'opt_values' param through Couch tags. One needs to use 'double quotes' for the enclosed Couch tags to be executed.

2. If you study the sample filtered search I mentioned, you'll find that the form lies just above the <cms:pages> block. Once it is successfully submitted, the form uses the submitted values to set some global variables that are used by the <cms:pages> block that follows. Your code is not doing that.

Following is some working code that rectifies those issues. It is filtering by folder and year. Please notice how the k_success block uses the submitted folder and year to set the global variables 'my_folder', 'my_start_date' and 'my_stop_date' eventually used in <cms:pages> listing that follows it.
Code: Select all
<cms:if k_is_list>
    <cms:form name="quicksearch" id="quicksearch" anchor='0'>
        <cms:if k_success >
                <cms:if frm_my_folder!='-' >
                    <cms:set my_folder = frm_my_folder  scope='global'/>
                </cms:if>
               
                <cms:if frm_my_date!='-' >
                    <cms:set my_start_date  = "<cms:show frm_my_date />-01-01"  scope='global'/>
                    <cms:set my_stop_date   = "<cms:add frm_my_date '1' />-01-01"  scope='global'/>
                </cms:if>
               
                <!-- debug info. Remove after testing -->
                <cms:show my_folder /><br>
                <cms:show my_start_date /><br>
                <cms:show my_stop_date /><br>
        </cms:if>   
       
        <div>
            <label>Folder</label>
            <cms:input
                type='dropdown'
                opt_values="Filter by Client=- | <cms:folders masterpage='project.php'><cms:show k_folder_title /> = <cms:show k_folder_name /> |</cms:folders>"
                opt_selected='-'
                name='my_folder' />
        </div>
        <div>
            <label>Year</label>
            <cms:input
                type='dropdown'
                opt_values="Filter by Year=- | <cms:archives masterpage='project.php' type='yearly'><cms:date k_archive_date format='Y' /> | </cms:archives>"
                opt_selected='-'
                name='my_date' />
        </div>
        <div class="buttonset">
            <cms:input type="submit" class="fbsubmitbtn" value="Start Searching!" name="submit"/>
        </div>
    </cms:form>
   
    <cms:pages masterpage='project.php' paginate='1' limit='9' folder=my_folder start_on=my_start_date stop_before=my_stop_date>
        <h2><cms:show k_page_title /></h2>
        ....
        <cms:no_results>
            No projects found
        </cms:no_results>
    </cms:pages>
   
</cms:if>

Hope this helps.
KK you saved me. Thanks so much. One last request: 1. I want to the search to trigger when I choose an option. I did this but it's not working
Code: Select all
<cms:input  onchange="this.form.submit()"
                type='dropdown'
                opt_values="Filter by Client=- | <cms:folders masterpage='project.php'><cms:show k_folder_title /> = <cms:show k_folder_name /> |</cms:folders>"
                opt_selected='-'
                name='my_folder' />


2. The list of projects is in a section close to the bottom of my website and has the ID projects-wrap. So I would want this "#projects-wrap" to be appended to the search url so that the page automatically jumps to the list of filtered news section instead of always going back to the top of the page and users have to scroll to the bottom again to see the filtered results. Thank you
7 posts Page 1 of 1