Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2006-09-24 03:36:27

deronsizemore
Member
From: Kentucky
Registered: 2005-11-02
Posts: 324

Having trouble with creating a separate section for search results

Okay, I realize how to do this partially. I got it to work by using <a href=“http://thresholdstate.com/threshold/3836/using-search-in-textpattern-rc3”>THIS</a>

The only thing I’m stuck on is that it says use <txp:search_input section="search" /> which is fine, but instead of using the txp tag for the search bar, I’m using a form with my own html. So, this is what I’ve got going on:

This code is in my page template where the search shows up: <txp:output_form form="site_search" /> and the “site_search” form including the html for the search is:

<code>
<form action=”<txp:site_url />” method=“get”>
<fieldset id=“search”>
<legend>Search</legend>
<label for=“query”>Search</label><br />
<input id=“query” name=“q” size=“22” type=“text” value=”“ />
<button type=“submit”>Search!</button>
</fieldset>
</form>
</code>
<br />

So since I’m not actually using the txp tag for the search, I’m wondering where I need to include “section=‘search’” so that the search results have a separate template?

Thanks

Last edited by deronsizemore (2006-09-24 03:37:41)

Offline

#2 2006-09-24 04:08:11

jm
Plugin Author
From: Missoula, MT
Registered: 2005-11-27
Posts: 1,746
Website

Re: Having trouble with creating a separate section for search results

A Better Textpattern Search

<code>
<form action=”/index.php” method=“get”>
<input type=“hidden” name=“s” value=“search” />
<input type=“text” name=“q” value=”“ size=“15” />
<input type=“submit” value=“search” />
</form>
</code>

Also, if you want section-specific search, just change the hidden input to <input type="hidden" name="s" value="<txp:section />" />

Last edited by jm (2006-09-24 04:09:55)

Offline

#3 2006-09-24 05:05:02

deronsizemore
Member
From: Kentucky
Registered: 2005-11-02
Posts: 324

Re: Having trouble with creating a separate section for search results

Okay, two questions.

1. Is there no way to make it work with the code I’ve already got? I’ve got quite a bit of CSS already for the form I’m using, and it would be a pain to start all over. If not, I’ll just have to leave it how it is and live with the results showing up on the default template.

2. If I’m looking for section-specific search (which I will be soon), how does it know what section to search? I see that it’s got value="<txp:section />" but how does that tell it what section to only search? Or do I have to do something like value="<txp:section_name />"?

Thanks

-Deron

Last edited by deronsizemore (2006-09-24 05:06:43)

Offline

#4 2006-09-24 05:56:40

jm
Plugin Author
From: Missoula, MT
Registered: 2005-11-27
Posts: 1,746
Website

Re: Having trouble with creating a separate section for search results

1. Just add <input type="hidden" name="s" value="search" /> and change the form action to index.php.

<code>
<form action=”/index.php” method=“get”> <input type=“hidden” name=“s” value=“search” /> <fieldset id=“search”> <legend=Search</legend= <label for=“query”=Search</label> <input id=“query” name=“q” size=“22” type=“text” value=”“ /> <button type=“submit”=Search!</button> </fieldset>
</form>
</code>

What’s actually happening:

  1. You’ve probably noticed the default search URL’s for TXP are <samp>http://site.com/?q=search+term</samp>. To get the search term – “q” – in the URL you need to get the variable from the form. Looking at the form, the input with name="q" is what puts it there. q=search term
  2. This brings us to <input name="s" type="hidden" value="search" />. s=variable, s=section (EX: sections in messy urls are accessed by site.com/index.php?s=section). Since it’s a hidden attribute, it won’t cause any display issues. The value, search, is the section name.
  3. Your search results will be located at <samp>http://site.com/index.php?s=search&q=search+terms</samp>

I think I answered your second question in #2. If you want the search form to search only the current section the user is in, use <txp:section /> as the value for the hidden input, as that will output the current section name (which will become the value for the <var>s</var> variable. If you want a specific section, just replace the hidden input’s value with plain text (eg. <samp>value=“courses”</samp>).

Last edited by jm (2006-09-25 03:13:23)

Offline

#5 2006-09-24 22:22:03

deronsizemore
Member
From: Kentucky
Registered: 2005-11-02
Posts: 324

Re: Having trouble with creating a separate section for search results

Thank you! I have it working now with a separate template from the homepage!

Honestly though, I’m still confused. I’m not a coder at all, so I didn’t understand a lot of what you told me. I’m trying to read and re-read, but much of it isn’t sinking in.

For starters, I don’t have any idea what search term “q” means or does and I also don’t know what a variable is? You said that s=section and s=variable, but I don’t know what that means either? I’m sorry.

I’m trying to play around with the search so that it will only search one section but that doesn’t seem to be working either. I changed value=search to value=courses as the value for the hidden input and it does not only search the “courses” section of my site. I did a test and other articles associated with other sections came up in the results when I did a search with the value set to “courses” when if I’m understanding it correclty, only two articles could have came up at the most because currently I’ve only got two articles associated with the “courses” section.

Thanks for all of your help! :-)

Last edited by deronsizemore (2006-09-24 22:22:38)

Offline

#6 2006-09-25 03:11:27

jm
Plugin Author
From: Missoula, MT
Registered: 2005-11-27
Posts: 1,746
Website

Re: Having trouble with creating a separate section for search results

That’s OK. Remember from algebra how x can be a value, like 2 or something (x+2=4)? That’s essentially how it is with coding, except x can be represented by qualitative data too, such as a text value. It’s that simple. In PHP, this is what it looks like:

<code>
$variable = “Joe”;
//this won’t do anything by itself
echo $variable;
//produces: Joe
</code>

Also, s=section. Your “courses” articles are posted in a category, not a section, which would mean you’d need to search by category.

Here’s an attempt at explaining the inner wokrings of the form. Try the actual URL’s on your site to see the effects.

<pre>
$q = “search terms”; HTML: &lt;input id=“query” name=“q” type=“text” /&gt; Search URL: http://kentuckygolfing.com/?q=search+terms

$s = “search”;//section name HTML: &lt;input type=“hidden” name=“s” value=“search” /&gt; &lt;input id=“query” name=“q” type=“text” /&gt; URL: http://kentuckygolfing.com/?s=search URL: http://kentuckygolfing.com/search/ Search URL: http://kentuckygolfing.com/?s=search&q=search+terms

$c = “courses”; HTML: &lt;input type=“hidden” name=“c” value=“courses” /&gt; &lt;input id=“query” name=“q” type=“text” /&gt; URL: http://kentuckygolfing.com/?c=courses URL: http://kentuckygolfing.com/category/courses Search URL: http://kentuckygolfing.com/?&c=courses&q=search+terms
</pre>

So each letter, “q,” “s,” and “c” is represented in the URL. They’re variables.

Really, all you need to do is copy paste the form above, then modify accordingly. If you want search results to appear in the section named search, use <input type="hidden" name="s" value="search" />. If you want to search a category, use <input type="hidden" name="c" value="categoryname" />. If you want to search both a section and category, use <input type="hidden" name="s" value="search" /><input type="hidden" name="c" value="categoryname" />. Just add any of those before the input with name="q".

BTW, I’m more a wannabe php coder than a halfway decent one :D.

Offline

#7 2006-09-25 03:49:43

deronsizemore
Member
From: Kentucky
Registered: 2005-11-02
Posts: 324

Re: Having trouble with creating a separate section for search results

Thank you for taking the time to try and explain that too me. Some of it I’m getting, but man I feel like an idiot looking at PHP. I know it’s not even suppose to be that hard, but I swear I just can’t wrap my brain around most of it! Pisses me off really cause I don’t feel like I’m that dumb! lol

The thing I’m still not getting is the whole “Your “courses” articles are posted in a category, not a section, which would mean you’d need to search by category.”

Unless I’m just completely confused, my courses articles (AJ Jolly Golf Course and Andover Golf and Country Club) are posted in the section named “courses”. These two articles do not have a category tied to them at all.

Let me explain what I’m trying to do here with txp and maybe we’ll be better on the same page. I might have confused you from the beginning.

On the homepage and for the most part, every other page on the site I’m going to the have the site search in the middle column which when someone searches for a term, it will take them to the results page and it will use the “search_page” template that I’ve made so that it looks different from the default homepage template.

Now, with that said, I’m going to have a section on the site called “Course Guide” where people can navigate to this section by clicking “course guide” in the navigation menu, then they will see a different search input in the left column of the site, similar to the one you see on the homepage in the middle column, only this search will ONLY search the articles associated with the “courses” section. What I’m doing here is that there are somewhere around 300 golf courses in Kentucky, each one of these courses will be in a separate article with all the info on the course. These articles wont be visible on the homepage or anything like that, they will only show up when someone goes to the “course guide” link and searches for a course that way.

Let me know your thoughts.

Thanks

Offline

#8 2006-09-25 05:22:02

jm
Plugin Author
From: Missoula, MT
Registered: 2005-11-27
Posts: 1,746
Website

Re: Having trouble with creating a separate section for search results

deronsizemore wrote:

The thing I’m still not getting is the whole “Your “courses” articles are posted in a category, not a section, which would mean you’d need to search by category.”

Oh, duh. Sorry, I went to the homepage, and saw “Filed in Courses” and assumed you only had the category. Forget about the whole c=courses bit. Actually, it’s probably best if you ignore my muddled explanation. The code is virtually the same as the above still, with the modifications made to fit your form.

Homepage search (and everywhere else) that uses the “search” section (which uses the search_page template)

<pre>
&lt;form action=”&lt;txp:site_url /&gt;” method=“get”&gt; &lt;input type=“hidden” name=“s” value=“search” /&gt;&lt;!—value=name of the section you want to search!—&gt; &lt;fieldset id=“search”&gt; &lt;legend=Search&lt;/legend= &lt;label for=“query”=Search&lt;/label&gt; &lt;input id=“query” name=“q” size=“22” type=“text” value=”“ /&gt; &lt;button type=“submit”=Search!&lt;/button&gt; &lt;/fieldset&gt;
&lt;/form&gt;
</pre>

Course guide/special searches

Now for the course guide section, use the same HTML, but change the second line (after form) to:

<code>
<input type=“hidden” name=“s” value=“the-name-of-the-section-you-want-to-search” />
</code>

That’s it.

Last edited by jm (2006-09-25 05:24:24)

Offline

#9 2006-09-25 13:40:50

deronsizemore
Member
From: Kentucky
Registered: 2005-11-02
Posts: 324

Re: Having trouble with creating a separate section for search results

hehe, no problem. I thought I probably confused you…cause I confuse myself with this half the time! I’ve got blog entries with a possible category of “courses” then I’ve got a section called “courses” which course details/info are associated with (not blog entries) and ahhh, just get’s confusing sometimes. I have to take a step back and think. Same goes for my “instruction” link which takes you to the “instruction” section. This section is just going to be a basic static page with some golf tips…but I’ve also got a category called “sections” for blog entries and if the visitor clicks the Filed In link of “instruction” is takes them to all the blog articles with instruction as the category, but the problem is that this page showing blog entries with category instruction is different than the instruction page that the navigation link will take you to…so I think it can get confusing for visitors. BUT, this is a whole ‘nother can of worms, which you can read about here: <a href=“http://forum.textpattern.com/viewtopic.php?id=18712”>http://forum.textpattern.com/viewtopic.php?id=18712</a> if you want! :-)
<br />
Thanks for the breakdown of code for each page!

I’ve got one last question and I’ll leave you alone with this. In your last post for the code you gave for my homepage search you said <input type="hidden" name="s" value="search" /><!--value=name of the section you want to search!-->. It seems contradicting to me. In one instance I’m using value=search so that my search results page template is different from the homepage because the search section uses search_page template. I got that.

But in the the other instance, I’m using value=the-name-of-the-section-you-want-to-search so that when I use it on my course guide section it only searches articles accociated with a certain section. So if this is true, by putting “value=courses” in the course guide template so that it searches only the articles associated with “courses” section, wouldn’t the code for the homepage/all other pages ONLY search the “search” section? And since there wont be any articles associated with the “search” section, no results will show up.

**Don’t get me wrong, everything you’ve gave me is working (not tried the course guide search yet). I’m just trying to better understand how it works.

Thanks

Last edited by deronsizemore (2006-09-25 13:44:02)

Offline

#10 2006-09-26 00:51:15

jm
Plugin Author
From: Missoula, MT
Registered: 2005-11-27
Posts: 1,746
Website

Re: Having trouble with creating a separate section for search results

Oh man, I seriously should’ve tested more. It’s contradictory because it doesn’t really work! I did some quick testing on your site, but I hadn’t used generic terms like “an”, so I assumed it would work. But it doesn’t, as the results show.

So, scratch the whole section-specific searching. Just use the first example that uses value=search. Sorry for creating an uneccessary amount of confusion based on false assumptions! :D

Last edited by jm (2006-09-26 00:51:50)

Offline

#11 2006-09-26 14:31:22

deronsizemore
Member
From: Kentucky
Registered: 2005-11-02
Posts: 324

Re: Having trouble with creating a separate section for search results

Hehehe. :-) No problem. Yeah the “value=search” was working fine and I’ve got it where I can edit the search results page template so all that is good to go. I’ll just cross the section specific search bridge when I come to it. I’m not ready to implement it yet anyway. I think I’ve got a couple good bookmarks that tell how to only search one section, so I should be able to get it.

Thanks for your help!

Offline

Board footer

Powered by FluxBB