Forum for discussing general topics related to Couch.
9 posts Page 1 of 1
hello, I've been referring to this post and thought it would be useful for my purposes.

The requirement is for events to be categorised - could be in more than 1 category - and for there to be the ability to filter the events by category. I have said to the client that I will lay the foundations for this functionality so that it can be implemented at some future date as the deadline is looming.

However I think I may have set it up incorrectly ... what I have is this:

whats-on.php which is the clonable template for each event - this has an editable region like this:
Code: Select all
<cms:editable name='event_category' type='relation' masterpage='event-categories.php' desc="check one or more of these, add new category using Event Categories link in the sidebar" label='EVENT CATEGORIES'  order='17'  />

event-categories.php is like this:
Code: Select all
<?php require_once( 'admin/cms.php' ); ?>
<cms:template title='Event Categories' clonable='1' order='47'></cms:template>
<?php COUCH::invoke(); ?>

whats-on.php is doing all the displaying of events - list view showing the event listing and page view the details of a single event. I am displaying the categories an event is in like so:
Code: Select all
<cms:related_pages 'event_category' >
<cms:if k_count gt '1'> &#124; </cms:if><cms:show k_page_title />

It is simply an extra piece of information about the event ... JAZZ for example - no links or functionality.

When I come to apply the 'filters' to allow the list view to display say just Jazz events or just Classical events I would want these filters / links to be in the whats-on.php template - like sub-navigation filters. BUT I've been having a bit of an experiment for another part of the site and it appears that the filtering functionality would work from within the event-categories.php and NOT from whats-on.php

I suspect I have set this up wrongly in order to apply filtering in the way described here - . It'll be hard to backtrack and say I can't do it now! Please could you advise if I've gone down the wrong path - many thanks!
Hi potato :)

You did not setup the templates wrong. In fact, you did exactly what was described in the post you mentioned. And the way things were setup in that post, it is indeed the 'tags' template that lists the filtered 'blog' posts.

The idea there was simply to duplicate what WordPress does - you invoke something like and get a listing of all 'jazz' posts (from blog template).

That said, it is entirely at your discretion as to where and how you wish to get the posts listed.
You wish to show the filtered listing on the events template itself, so let us do just that.

NOTE: I'm assuming you are using Couch v1.4.5RC1/2, as described in the original post

OK so, as you mentioned, the list-view of your events template (whats-on.php) is already listing out the events. The part of the code that does that would look essentially something like this -
Code: Select all
<cms:pages limit='10'>
   <h2><cms:show k_page_title /></h2>

If I were to make a slight modification to the code above to make it as follows, the listing will only show pages related to 'jazz' (the 'event_category' being your 'relation' editable-region's name). I think that should be straight-forward to understand.
Code: Select all
<cms:pages limit='10' custom_field="event_category=jazz">
   <h2><cms:show k_page_title /></h2>

In the code above we had hard-coded the term 'jazz'. Let us change it to fetch the value dynamically from the URL -
Code: Select all
<cms:set my_category="<cms:gpc 'category' method='get' />" />

<cms:pages limit='10' custom_field="event_category=<cms:show my_category />">
   <h2><cms:show k_page_title /></h2>

in the code above, we are checking the URL used to access the current template for a querystring parameter named 'category' and then using whatever value is specified in it to filter our listing.

To test it out, if the current URL happens to be
make it
and now when you access the events listing it will show it filtered by 'jazz'.

Of course, that now gives us the ability to manipulate the URL dynamically.
So, for example, the following will show a listing of only events related to 'classical'

If you followed whatever was described above, you'll realize that now we only have to generate a 'menu' showing pages from the 'events-categories.php' template where each item will actually link to the 'whats-on.php' template's list-view and only add its name as the 'category' parameter and we are done.

This is how we can do that -
Code: Select all
<cms:set my_events_template_link="<cms:link  'whats-on.php' />" />

<cms:pages masterpage='event-categories.php'>
    <li><a href="<cms:add_querystring my_events_template_link "category=<cms:show k_page_name />" />"><cms:show k_page_title /></a></li>

And that should give you a menu showing the categories that you can use to filter the events listing.

Hope it helps.
I am so grateful for your detailed and helpful reply, I'll try it all out tomorrow and let you know the results My confidence has been restored! Thank you :)
This works perfectly - your step by step explanation has made it very clear how it functions too. Thanks a million @kk
You are always welcome, potato :)
Glad I could help.
Hi KK,
How do I check if a page is in "tags view" so i can show out put the title of the tag and also show it in the breadcrumb. I used the tags to filter pages on the list-view. Thanks
I was able to use the code below to check the tags-filtered listview page: But the tag name was not outputted. What did I do wrong?
Code: Select all
<cms:if k_is_home >
  <-- Output tag name -->
  <cms:show k_page_title />
Check spelling in k_page_title
I corrected it but still couldn't get the tag name to output on the front-end
9 posts Page 1 of 1

Who is online

In total there are 9 users online :: 0 registered, 0 hidden and 9 guests
(based on users active over the past 5 minutes)

Users browsing this forum: No registered users and 9 guests