Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2008-01-10 08:34:47

mikkeX
Archived Plugin Author
Registered: 2004-02-26
Posts: 74

Search category only

I have this search page:

http://www.etc.se/textarkivet/

If I type something in the search field I could search a specific category, but if I do not type anything in the search field and just choose a category I am suddenly on the frontpage when I do the search. So is it possible to just list articles from one category on the search page? Can you use some kind of wildcard to make it work on the search page?

Last edited by mikkeX (2008-01-10 08:35:24)

Offline

#2 2008-01-10 09:42:50

Mary
Sock Enthusiast
Registered: 2004-06-27
Posts: 6,236

Re: Search category only

Yes, it is possible. You can do it by building your own search form, then adding to it:

<input type="hidden" name="c" value="the_category_name_here" />

Offline

#3 2008-01-10 09:53:29

mikkeX
Archived Plugin Author
Registered: 2004-02-26
Posts: 74

Re: Search category only

Thanks for the reply, but it is not what I am looking for, and it does not work on the site. My english is not so good, but I will try to exemaple better.

I have the categories in a drop down list.

When I do a search with something in the search field and choose a category it works, for example:
http://www.etc.se/?c=debatt&sort=relevans&q=johan

That works fine, but if I only want to search a category for every article in section ‘debatt’ it does not work:
http://www.etc.se/?c=debatt&sort=relevans&q=

So if the search field is empty I do not get any results from do a search for everything in the category.

Offline

#4 2008-01-10 10:12:34

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: Search category only

Er – ofcourse it returns empty as your q is empty. You have to search something to return something when searchin something. Example, You can’t eat pizza if you don’t have pizza.

It can be done with php-redirect. So, add to the top of your page template (I mean it – to the top):

<txp:php>
	if(gps('q') == '' && gps('c') && gps('sort')) {
		$path = site_url().'?c='.gps('c');
		header("HTTP/1.x 301 Moved Permanently");
		header("Status: 301");
		header("Location: ".$path);
		header("Connection: close");
	}
</txp:php>

Cheers!

Last edited by Gocom (2008-01-10 10:13:51)

Offline

#5 2008-01-10 10:15:47

mikkeX
Archived Plugin Author
Registered: 2004-02-26
Posts: 74

Re: Search category only

Thanks Gocom, but still, that are not what I am looking for.

I want to list every article from a specific category (categories in a select-list) on the search page. That is possible to do with many CMS so it should be no problem with Textpattern, or?

Offline

#6 2008-01-10 10:19:38

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: Search category only

No, that is what you’re after as you can’t show any articles when the url has ?q= as it’s question and doesn’t return anything as it’s empty. That snippet of mine just removes the ?q if it’s empty.

You need <txp:article /> to show the articles. But no you cannot have ?q= and ?c= at same time if q is empty. Made a section for the search if you want to show something stylish, or use if_category-tags.

Cheers!

Last edited by Gocom (2008-01-10 10:20:58)

Offline

#7 2008-01-10 10:44:28

mikkeX
Archived Plugin Author
Registered: 2004-02-26
Posts: 74

Re: Search category only

So where are no way to use wildcards on search in Textpattern?

Offline

#8 2008-01-10 10:50:01

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: Search category only

What do you mean with wildcard? Random? Yes, in many ways. Example:

<txp:if_search><txp:else /><txp:if_category><txp:article sort="rand()" /></txp:if_category></txp:if_search>

And your wildcard search is finished.

But where do you need the empty q. As the c is enough. After that everything ie. styling, is up to you. Textpattern is flexible, not pre-made and stoned portal ;). In textpattern sorting and styling isn’t based on the form, it’s based on the outputting tag.

Cheers!

Last edited by Gocom (2008-01-10 10:51:26)

Offline

#9 2008-01-10 12:03:15

mikkeX
Archived Plugin Author
Registered: 2004-02-26
Posts: 74

Re: Search category only

No wildcard, as in search for any character
http://en.wikipedia.org/wiki/Wildcard_character#Computing

Offline

#10 2008-01-10 14:12:45

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: Search category only

<txp:article sort="rand()" /> is wildcard…. it does same as “search for anything”…

Last edited by Gocom (2008-01-10 14:13:17)

Offline

#11 2008-01-10 14:16:39

mikkeX
Archived Plugin Author
Registered: 2004-02-26
Posts: 74

Re: Search category only

It is not any article I am after, it is to search for any article with wildcard search instead for searching for a word in the searched category. Random article just give me a random article… If I use wildcard direct in Mysql you use ‘%’ but that is not possible in my installation of Textpattern

Offline

#12 2008-01-10 14:41:44

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: Search category only

Random article just give me a random article

And there is no way for search empty as it searches for empty, aka non. But, yes you can’t search ?q=My % article… nor you can’t just let the wheell of fortune to deside which word to use.

But first you were after:

  1. Searching within category
  2. Searching category with out search word
  3. Searching everything inside category
  4. Searching everything with wildcard
  5. Searching everything within category with wildcard

Just to point out that your question have changed during the time. Maybe it’s just because native language or something… ;)

Cheers!

Last edited by Gocom (2008-01-10 14:51:41)

Offline

Board footer

Powered by FluxBB