Support Forums

Modification: Display Search String on Search Results Page

This is a discussion on Modification: Display Search String on Search Results Page within the Modules / Plugins / Modifications forums, part of the Developer Forums category; Hey everybody, want to add what a user searched for at the top of the search results page? It would ...


Go Back   68 Classifieds Forums > Developer Forums > Modules / Plugins / Modifications

Reply
 
Thread Tools Display Modes
Old 06-30-2008, 11:33 PM   #1
Member
 
Join Date: May 2008
Location: Madison, WI
Posts: 77
Rep Power: 11
jonahcoyote is on a distinguished road
Lightbulb Modification: Display Search String on Search Results Page

Hey everybody, want to add what a user searched for at the top of the search results page? It would provide good feedback to the user and also as a reminder for what they searched for in case they want to search for something else.

All you have to do is edit 2 files, searchresults.php and showlistings.tpl.

STEP 1: Get the data. Open searchresults.php and around line 41 insert this code:

Code:
$class_tpl->assign('searchstring', $_REQUEST['searchtext']);
This gets searchtext and assigns it to a variable called searchstring.

STEP 2: Display in the template. Open showlistings.tpl and around line 83 (after the foreach results logic and before your first <tr>) insert this:

Code:
{if $file=="searchresults.php"}
    <h3>Search Results</h3>
    <em>You searched for: {$searchstring}</em>
    {/if}
The {if} checks to see if we are on searchresults.php and not category.php - If we are, then I display a header and then a little text "You search for..." and then my $searchstring variable which I assigned in the first step.

Voila! Search results displayed! I believe you could also get the rest of the search data and build a little table showing the user all the search parameters they used. Just use:

Code:
$class_tpl->assign('searchstring', $_REQUEST['searchtext']);
And replace searchstring and searchtext with the data you want. You'll also need to add code to your showlistings.tpl file to display the data but if you've followed so far, I think you'll probably know how to do that.

Cheers,
Jonah
jonahcoyote is offline   Reply With Quote
Old 07-01-2008, 04:50 PM   #2
68 Classifieds Staff
 
Eric Barnes's Avatar
 
Join Date: Mar 2006
Location: Belmont, NC
Posts: 5,493
Rep Power: 131
Eric Barnes is just really nice Eric Barnes is just really nice
Default

Just for reference you can add the following to your template file:
<em>You searched for: {$smarty.get.searchtext}</em>
__________________
Eric Barnes
68 Classifieds Developer
Customer Area | Issue Tracker | Documentation | 68C Mods | 68 @ Twitter | My Modules
Eric Barnes is offline   Reply With Quote
Old 07-02-2008, 01:06 PM   #3
Member
 
Join Date: May 2008
Location: Madison, WI
Posts: 77
Rep Power: 11
jonahcoyote is on a distinguished road
Default

Awww man, thanks for the shortcut! Is this documented anywhere? How would anyone else know how to do something like this?

- Jonah
jonahcoyote is offline   Reply With Quote
Old 07-02-2008, 01:09 PM   #4
curmudgeon
 
Join Date: Mar 2006
Posts: 5,305
Rep Power: 131
Lhotch is a glorious beacon of light Lhotch is a glorious beacon of light Lhotch is a glorious beacon of light
Default

Quote:
Originally Posted by jonahcoyote
Awww man, thanks for the shortcut! Is this documented anywhere? How would anyone else know how to do something like this?

- Jonah
Its documented in a sense, I personally forgot about it.

Its actually a function of the smarty templates and not 68C specific.

http://www.smarty.net/manual/en/lang...les.smarty.php
__________________
Larry

Knowledge learned is more valuable than knowledge given.
Lhotch is offline   Reply With Quote
Old 07-20-2008, 04:31 PM   #5
Senior Member
 
Join Date: Jun 2007
Posts: 110
Rep Power: 16
crystal is on a distinguished road
Default

This is a good mod for keywords, but if you search extrafields with no keywords the search results will look like:

Search Results
You searched for:

I have a few extrafields that pretty much take care of the need for keywords if you're on the search form, so I think a lot of users would see a blank. Now if only I could get all of the info from the search (including extrafields) to show up after 'you searched for'...
__________________
Crystal
v4.0.8 Dev
crystal is offline   Reply With Quote
Old 07-20-2008, 09:01 PM   #6
68 Classifieds Staff
 
Eric Barnes's Avatar
 
Join Date: Mar 2006
Location: Belmont, NC
Posts: 5,493
Rep Power: 131
Eric Barnes is just really nice Eric Barnes is just really nice
Default

In that case you can just wrap an if statement around it:
Code:
{if $file=="searchresults.php" && $searchstring}
    <h3>Search Results</h3>
    <em>You searched for: {$searchstring}</em>
{/if}
__________________
Eric Barnes
68 Classifieds Developer
Customer Area | Issue Tracker | Documentation | 68C Mods | 68 @ Twitter | My Modules
Eric Barnes is offline   Reply With Quote
Old 07-20-2008, 09:18 PM   #7
Senior Member
 
Join Date: Jun 2007
Posts: 110
Rep Power: 16
crystal is on a distinguished road
Default

Quote:
Originally Posted by suzkaw
In that case you can just wrap an if statement around it:
Code:
{if $file=="searchresults.php" && $searchstring}
    <h3>Search Results</h3>
    <em>You searched for: {$searchstring}</em>
{/if}
Hmm.... I tried that and nothing shows at all now, even when just typing in a keyword.
__________________
Crystal
v4.0.8 Dev
crystal is offline   Reply With Quote
Old 07-21-2008, 07:56 AM   #8
All Hands On Deck
 
 
Join Date: Mar 2008
Posts: 2,915
Rep Power: 71
seymourjames is a jewel in the rough
Default

Picking your way through this and you will be able to do a lot more with search results including putting searchtext directly into the body of the page which is a good thing to do. I put this at the top of my layout.tpl file in the header. It is cumbersome but a way to better optimise pages. You can see the effect by going here properties for sale in france and doing some searches.

{if $SCRIPT_NAME == "/searchresults.php"}
{assign var=Seller value=$smarty.get.owner}
{assign var=Text value=$smarty.get.searchtext}
{assign var=Property value=$smarty.get.opt1}
{assign var=Type value=$smarty.get.type}
{assign var=Sorty value=$smarty.get.sortorder}

{if $Type == 30}{assign var=Type value="south west france"}{/if}
{if $Type == 1}{assign var=Type value="aquitaine"}{/if}
{if $Type == 11}{assign var=Type value="limousin"}{/if}
{if $Type == 14}{assign var=Type value="midi-pyrenees"}{/if}
{if $Type == 34}{assign var=Type value="north france"}{/if}
{if $Type == 42}{assign var=Type value="north calais"}{/if}
{if $Type == 43}{assign var=Type value="picardy"}{/if}
{if $Type == 33}{assign var=Type value="east france"}{/if}
{if $Type == 46}{assign var=Type value="alsace"}{/if}
{if $Type == 48}{assign var=Type value="burgundy"}{/if}
{if $Type == 44}{assign var=Type value="champagne"}{/if}
{if $Type == 47}{assign var=Type value="franche-comte"}{/if}
{if $Type == 45}{assign var=Type value="lorraine"}{/if}
{if $Type == 32}{assign var=Type value="south france"}{/if}
{if $Type == 50}{assign var=Type value="provence alps azur"}{/if}
{if $Type == 10}{assign var=Type value="languedoc roussillon"}{/if}
{if $Type == 49}{assign var=Type value="rhone alps"}{/if}
{if $Type == 51}{assign var=Type value="auvergne"}{/if}
{if $Type == 31}{assign var=Type value="west france"}{/if}
{if $Type == 39}{assign var=Type value="brittany"}{/if}
{if $Type == 41}{assign var=Type value="normandy"}{/if}
{if $Type == 38}{assign var=Type value="pays de loire"}{/if}
{if $Type == 19}{assign var=Type value="poitou chaente"}{/if}
{if $Type == 35}{assign var=Type value="central france"}{/if}
{if $Type == 37}{assign var=Type value="corsica"}{/if}
{if $Type == 36}{assign var=Type value="paris"}{/if}
{if $Seller}
{if $pageNum == 1}
<title>French Property Sales - {$Seller}</title>
{else}
<title>French Property Sales - {$Seller} - {$pageNum}</title>
{/if}
{assign var=newtitle value="French Property Sales - $Seller - $pageNum"}
<meta name="Description" content="Wonderful properties in France with French property seller {$Seller} - Page {$pageNum}" />
<meta name="Keywords" content="property,france,properties,french" />
{else}
{if $Property == NULL}{assign var=Property value="houses"}{/if}
{if $Type == NULL}{assign var=Type value="properties"}{/if}
{if $Sorty == NULL}{assign var=Sorty value="house"}{/if}
{if $Text == NULL}{assign var=Text value="homes"}{/if}
{if $pageNum == 1}
{assign var=newtitle value="French Property - ($Type - $Text - $Property - $Sorty)"}
<title>{$newtitle})</title>
{else}
{assign var=newtitle value="French Property - ($Type - $Text - $Property - $Sorty - $pageNum)"}
<title>{$newtitle})</title>
{/if}
<meta name="Description" content="Search for a wonderful property in France with + {$Text} + {$Property} + {$Type} + {$Sorty} - {$pageNum}" />
<meta name="Keywords" content="property,france,properties,french,{$Text} ,{$Property},{$Type}" />
{/if}

In the search.tpl file I then use the $newtitle variable for example in the body of the page.

What would be nice is if I knew how to get the name of the actual seller for example and not just a number. The same issue applied for categories but that is a finite number and possible to define and test for more easily.
__________________
"The fool doth think he is wise, but the wise man knows himself to be a fool.".

TemplateCodes.com for 68 Classifieds
The SEO Book for all your search engine optimization needs
seymourjames is offline   Reply With Quote
Old 07-21-2008, 08:30 AM   #9
curmudgeon
 
Join Date: Mar 2006
Posts: 5,305
Rep Power: 131
Lhotch is a glorious beacon of light Lhotch is a glorious beacon of light Lhotch is a glorious beacon of light
Default

Quote:
Originally Posted by seymourjames
What would be nice is if I knew how to get the name of the actual seller for example and not just a number. The same issue applied for categories but that is a finite number and possible to define and test for more easily.
The sellers ID is stored in the ad table itself and is also in the sellers table. This allows the tables to be linked by a common key. When seeing ads listed in bulk etc the user table isnt queried. To get the sellersname you would have to edit the query in the underlying script and do a table join on userid in the query to pull the actual name.
__________________
Larry

Knowledge learned is more valuable than knowledge given.
Lhotch is offline   Reply With Quote
Old 07-21-2008, 10:17 AM   #10
All Hands On Deck
 
 
Join Date: Mar 2008
Posts: 2,915
Rep Power: 71
seymourjames is a jewel in the rough
Default

What would that look like roughly?
__________________
"The fool doth think he is wise, but the wise man knows himself to be a fool.".

TemplateCodes.com for 68 Classifieds
The SEO Book for all your search engine optimization needs
seymourjames is offline   Reply With Quote
Reply

Tags
display search string , search data , search information

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
MODIFICATION: Display your extra fields on the showlistings.tpl page cwp Modules / Plugins / Modifications 28 08-06-2009 12:42 PM
Display Search String on Results Page jonahcoyote Technical Support 3 06-30-2008 11:26 PM
Display Both SEARCH AND BROWSE on same page megapix Technical Support 2 03-23-2008 01:04 PM


All times are GMT -4. The time now is 01:35 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0