Coded something up in Couch in an interesting way? Have a snippet or shortcode to share? Post it here for the community to benefit.
61 posts Page 1 of 7
Previous 1, 2, 3, 4, 5 ... 7 Next
Okay i'll try explain what I'm after.

I have a section where i list trackdays. I'm currently using editable tags for the page.
They would then output into the trackday_list page.

Now i don't know how to go around filtering to make it easy for the customer to find.

I have the editable's.

Location
Date [manually inputted date]
Type [cars,bikes]
Dba [sound limit]

Now they are all listed like clonepages, however i want the customer to be-able to filter the options out in a dropdown menu. I would want to filter them above out. So the customer can use a dropdown menu to section then only show lets say filter location=cadwell park or filter by the date and show all that are on that date.

Any ideas on filtering this out.
Hi Simon,

I'm interested in this also, I believe cheesypoof built an automotive site that had a pretty sweet search, I'd love to see a "how to" on filtering and building and advanced search / filter. This would really demonstrate the power of couch, because it's so easy to add fields to clonables and utilise opt_values from other clonables.
Hi,

The cms:pages tag (Couch's workhorse for listing pages) also supports finding pages based on contents of their editable region using its 'custom_field' parameter.

So, for example, if a property listing site has the following custom fields in its property template -
    locality
    property_type (e.g Commercial, residential etc.)
    price
    num_of_bedrooms
    num_of_bathrooms
    plot_area

the following code would fetch all property entries that are commercial, with 5 bedrooms or more and a plot area of 7000 units or more.
Code: Select all
<cms:pages  custom_field="property_type==Commercial | num_of_bedrooms>=5 | plot_area>=7000"  >
   ...
</cms:pages>

Of course, the 'filter' criteria in the snippet above is hard-coded and so does not help in doing exactly what you want.
However, if we could somehow dynamically cobble together the value we feed into the custom_field parameter using the visitor's input, we are there.

To demonstrate one way of doing exactly this, I've put together a small fully working property template. It is bare-bone with no styling etc. so as to keep the focus only on the topic at hand.

The attached zip has two file - the 'property.php' template and a snippet used by it named 'search.htm'.
Please download and place the 'property.php' template in your root folder and the 'search.htm' snippet in your 'couch/snippets' folder (or whatever snippets folder you've specified in config.php).

The template 'property.php' defines several editable regions pertaining to property (e.g. price, area etc.).
The 'search.htm' snippet creates a form that shows these parameters and allows the visitor to specify his choice.
On submission, the selected values are used to fabricate a search string in a format accepted by the 'custom_field' parameter and then this search string is fed to the cms:pages tag loop to fetch in the matching pages.

Add a few properties and test out the search form on the front end -
search.gif
search.gif (3.23 KiB) Viewed 32345 times

I am sure this will serve as a working example which you can use as a basis for your own search.

Hope this helps.
Do let me know.

Thanks.

Attachments

Neat solution to build up a string for the custom_field parameter; thanks KK.
Neat. This helped me a lot.

out of curiosity what of those blog entries we see around which have multiple "tags", where as the same blog entry falls under multiple tags such as Gaming, Sci-Fi, Technology, Lifestyle...

Using <cms:folder ...> I know I can set a blog category but how do I achieve the multiple tags thing?

I assumed clicking on one of the above mentioned tags would require some sort of filtered search also, hence my posting this here.

Hope this makes sense am bad at putting ideas to paper...textarea. Lol
---
You live many times, but only ever remember your lives.length - 1
---
Image
@cholasimmons
We can use the 'relation' field set to many-to-many to create a multi-category listing (like tags) -
http://www.couchcms.com/docs/concepts/r ... ships.html.
Thanks.

Hope the downloadable documentation gets updated too
---
You live many times, but only ever remember your lives.length - 1
---
Image
Ok I've ran into a problem, I'll share my code in a minute when I get on a PC (I'm using my phone now)
My "find.php" file is set up pretty close to the "search.htm" from the downloadable example, so is my "gallery.php" as is "property.php".
No matter what selection I make in the search form, once I click on search, the results are not of what I searched for but of everything available under property.php. My search criteria is ignored entirely, the URL contains the "my_search_str" data though, such as ?locality=arizona&price=10000&bedrooms=3 e.tc... Even the empty fields appear alongside the entered fields, e.g: ?locality=-&price=-&bedrooms=-

And The debugging string isn't displaying anything, (<cms:show my_search_str/>)

Any ideas?
---
You live many times, but only ever remember your lives.length - 1
---
Image
@cholasimmons, since the 'my_search_str' variable is coming up blank, it is no wonder no constrains are being imposed on the search and you get back all the pages.

As for the solution, we'll have to look at the cms:form code where the 'my_search_str' gets pieced together and try to find what is going wrong.

PM me your templates if you have trouble finding the problem.

Thanks.
I've been trying to crack this before anyone else does, day in day out without much success.
One addition I made to my "search.htm" (find.php) is in the <cms:form...> tag after anchor='0' I added action='<cms:show k_site_link />gallery.php' so that when SEARCH is clicked on, tha results are displayed on the gallery list view, which is basically like "property.php" from KK's example.
I did this coz every single page on the site has find.php embeded on them, omitting that action I mentioned above causes the search results to be generated on the very same page you were on, but no results get displayed.


Additionally.
I setup the following code in my find.php so that it doesn't hav to be manually updated with how many states to display under locality, or how many bedrooms for example...
Code: Select all
<cms:pages masterpage='gallery.php'>
  <cms:set all_locality="<cms:concat all_locality ' | ' locality />" scope='global' />
</cms:pages>

The code works fine except for one tiny problem that I am unable to fix.
The code iterates through all the pages under gallery.php and extracts only the states from the editable region called locality and compiles them for use in the dropdown list of find.php
Code: Select all
<cms:input type="dropdown" name='locality' id='locality' opt_values="Any=- <cms:show all_locality/>" />

This way only the states entered in property.php show up in the dropdown list rather than states that are manually entered yet don't have property available in them. The problem is if the same state is entered more than once, for different property, the dropdown list will display that state more than once too, e.g: Ndola, Lusaka, Lusaka, Kitwe.

THIS is what I need help resolving. States must not appear again if they already exist.

(This is tiring typing from a blackberry omg)
---
You live many times, but only ever remember your lives.length - 1
---
Image
Previous 1, 2, 3, 4, 5 ... 7 Next
61 posts Page 1 of 7
cron