Textpattern tips, tutorials and code snippets

Search using non-default section

This TXP tips covers the same ground as the previous tip on Search with Textpattern, but uses a separate section and page for the search results.

The Textpattern default method (which uses the default page to display search results) may work well for you, but in case you want to separate your search results (SEO reasons for example), follow the simple steps below.

Create your search form

<h2>Site search</h2>
<txp:search_input label="" section="search" button="Go" size="15" wraptag="p" /> 

Create your search page template

In your Presentation tab, create a new page called search.

Create a search section

In your Sections tab, create a new section called search and set all options to no. Choose search as the page to use.

Place the search results code in your search page template

<txp:article limit="10" pgonly="1" />
<h2><txp:search_result_count text="search results" /> for "<txp:page_url type="q" />"</h2>
<txp:article limit="10" />
<p><txp:older>&raquo; Next results &raquo;</txp:older></p>
<p><txp:newer>&laquo; Newest results &laquo;</txp:newer></p>

Place the search form in your page templates

Wherever you want the search form to appear in your various page tenplates, call it using <txp:output_form form="search" />.

6 Comments Comment feed

How do I use this when making use of Sticky articles?!


Have you checked the Documentation for the article tag?

It has a searchsticky="boolean" attribute you might want to try.

  • Randy
  • 11 August 2011

I am using the tutorial for my current project to handle search results – and it worked like a charm. Ten search results displayed on the first page. My problem is that when I try to go to page 2 (…/search/2/) or any page down the line —- it kicks me to the generic article list found in the default article form.

Initally, I thought it may have something to do with <txp:newer>/<txp:older> tags, but I get the same results when using the soo_page_numbers plugin

Any guidance or feedback would be greatly appreciated.

I’m glad you got it working!

Thanks! Worked like a charm!

  • Edward
  • 20 January 2013

I don’t know if this is applicable but to stop textpattern from defaulting to the “default” page you may need to edit your “search_input” form like so:

<form role=“search” method=“get” action=”<txp:site_url/>”> <input id=“search-textbox” type=“search” name=“q”<txp:if_search> value=”<txp:search_term />”</txp:if_search>><input type=“submit” value=”<txp:text item=‘go’ />”>

<form role=“search” method=“get” action=”<txp:site_url/><txp:section name=“search” />”> <input id=“search-textbox” type=“search” name=“q”<txp:if_search> value=”<txp:search_term />”</txp:if_search>><input type=“submit” value=”<txp:text item=‘go’ />”>

I had to point the “search_input” form to the “search” section by adding <txp:section name=“search” /> after the “action” attribute.

Don’t know if this helps anyone but i was getting duplicated results and all sort before I did that…

Add a comment

Use Textile help to style your comments