Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2009-07-20 18:08:17

fbenza
New Member
Registered: 2009-07-20
Posts: 3

Search Filter

Hello. I have my site that has a music catalog in it.. and i want to make some search filters so I can search by author, song or album.. There is a way to do this with the default search or with some kind of plugin???
Thanks

Offline

#2 2009-07-20 20:32:55

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,454
Website GitHub

Re: Search Filter

fbenza wrote:

i want to make some search filters so I can search by author, song or album..

There are a number of ways to approach it and it depends on your ingenuity. The easiest way is by custom field: set each of those 3 items to be a custom field and then use the built-in tags (article_custom?) to help find them.

If you want to get a little freakier, the following might give you some ideas, although some of them are a little cumbersome depending on how many articles there are in your database:


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#3 2009-07-21 20:09:27

fbenza
New Member
Registered: 2009-07-20
Posts: 3

Re: Search Filter

Hi, thanks for answer me. i’m a begginer in this cms and the problem is add the three custom_field into the search to have a radio button and then
the search input take the value of one of the radio button and get the resulf of this search. The radio button would be the parameter for the search.
I know that the syntax is wrong but can someone tell me how i can do this with the three custom_field or which files i’ll need change?
Thanks

Here is the bad code:
<div id=“header_search”> <!— Start the search form —> <txp:search_input label=“Search maranathamusic.com” button=”“ size=“30” /> <txp:custom_field name=“search_artist” /> (This will be radio button) <txp:custom_field name=“search_album” /> (This will be radio button) <txp:custom_field name=“search_song” /> (This will be radio button)

</div><!— end the search form —>

Offline

#4 2009-07-21 20:39:18

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,454
Website GitHub

Re: Search Filter

fbenza wrote:

the search input take the value of one of the radio button and get the resulf of this search.

Sadly, you can’t use TXP to do this type of search using the search_input tag. By default, that only searches the article body and title (I think, perhaps the excerpt too). For this type of search you need to do it by hand.

First of all you’ll need an input form, inside that you’ll put something like this (untested):

Search maranthamusic.com <input type="text" name="q" />
<input type="radio" name="search_cf" value="artist" />Artist
<input type="radio" name="search_cf" value="album" />Album
<input type="radio" name="search_cf" value="song" />Song
<input type="submit" />

When you submit your form, your URL might contain site.com?q=Madonna&search_cf=artist

The 2nd stage is to get those variables in. The ‘q’ part should be available automatically if you wrap your code in <txp:if_search /> tags. Then all you need to do is grab the search_cf field (use the adi_gps or smd_if plugins for this) then use one of the techniques I outlined in my post above to search the given custom field.

Hope that helps.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#5 2009-07-22 21:11:04

fbenza
New Member
Registered: 2009-07-20
Posts: 3

Re: Search Filter

Hi, thanks for your answers. Im advancing but still having some problems

I know that i’m not smart for do this, but the syntax and the core is my problem.

Here are the codes.

On the header exist a for with this code:

<form method=“get” action=“http://nameofsite.com/”>
<input type=“text” name=“q” value=”“ size=“30” /><br />
<input type=“radio” name=“search_cf” value=“artist” />Artist
<input type=“radio” name=“search_cf” value=“album” />Album
<input type=“radio” name=“search_cf” value=“song” />Song
</form>

then, in the page sections in the default page i have this code

<div id=“static”> <div id=“static_title”> <txp:text item=“search_results” />: <txp:page_url type=“q” /> </div> <txp:adi_gps name=“search_cf” quiet=“1” /> <txp:adi_gps name=“q” quiet=“1” /> <txp:if_variable name=“search_cf” value=“artist”> <div id=“list_text”> <div class=“hfeed”> <txp:article category=“news” searchform=“search_artist_results” /> </div> </div>
</div>

Offline

Board footer

Powered by FluxBB