Modification: Display Search String on Search Results Page

Discussion in 'Modules / Plugins / Modifications' started by jonahcoyote, Jun 30, 2008.

  1. jonahcoyote New Member

    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
  2. Eric Barnes Guest

    Just for reference you can add the following to your template file:
    <em>You searched for: {$smarty.get.searchtext}</em>
  3. jonahcoyote New Member

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

    - Jonah
  4. Lhotch curmudgeon

    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/language.variables.smarty.php
  5. crystal Customer

    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'...
  6. Eric Barnes Guest

    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}
    
  7. crystal Customer

    Hmm.... I tried that and nothing shows at all now, even when just typing in a keyword.
  8. seymourjames All Hands On Deck

    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.
  9. Lhotch curmudgeon

    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.
  10. seymourjames All Hands On Deck

    What would that look like roughly?
  11. Lhotch curmudgeon

    you need the developer version to se the underlying scripts.
  12. crystal Customer

    Wow, thanks for posting. I am going to play around with this. I see how you have the keywords at the bottom of the page. I am hoping to put them in the search results so the user can see what they searched for.

    One question... I am a complete noob when it comes to SEO. Do search engines pick up all of those keywords? It seems like they are only generated when a user does a search, so will the spiders be able to see them? I'm not sure how that works.

    I do have the SEO mod on my site, but I wonder how effective it is and if the search engines are picking up those html pages, because they are still generated on the fly when a user requests them. Do search engines see content stored in a database? For instance all of the extra pages are numbers (no keywords in the title), and all of the content is stored in the database. Can a spider see the page content at all? Thanks for your help!
  13. seymourjames All Hands On Deck

    I try to liberally scatter keywords or key phrases which are present in the title tag or meta description into the body of the page (the content). I also try to make sure that one of the last things a search engine sees on a page is something relevant. Not the tile tag exactly but something close.

    In 68C your pages are created dynamically on the fly so to speak. The answer is yes, google sees them providing it can reconstruct them and knows about them. It is a good practice to create a sitemap so search engines can get to those pages (create them). If you have important search results pages you can give these as well but do not spam them with millions of searchresults. Especially if you end up with lots of blank pages or duplicates. It is not hard to make a script to generate millions of pages from your search results but I would not recommend doing this. Just a few dozen good ones; you should also think about making an XML sitemap and giving that to google every so often.

    The next part of your question is more controversial. From an SEO standpoint are html pages with keywords in the url better. Many would say yes and some would say - makes no difference. I lean towards yes. The effect may not be big but every little helps in my opinion. What is more important for sure is the title and content of the pages themselves, the use of your key phrases within the content of a page (keyword density, use of language, use of h1 and h2 headings, etc), the layout of the content on a page and the internal linking structure of your site (is it made for people). all of that but much is also dependent upon what happens away from your site (quality of inbound links - do not get confused though about page rank - think relevance of the links coming to you - links from on topic sites are much more valuable in general).
  14. crystal Customer

    Sitemaps rock!

    Thank you seymourjames for your advice! I have the v4 sitemap mod installed but I never really understood the functinoality of it. I submitted it to Google and Yahoo when I first installed. I just checked on Google, and it gave me a report of all the keywords in my pages, placement, and other stats that were very useful! Now I can see the spiders will pull those keywords! The sitemap is showing the URLs of all of my categories and ads.

    I am pretty impressed with the sitemap mod and the way it works with Google. I just had to give it some time to generate all of those reports. (It's been about 2 months since I installed it and submitted it (using the links that come with the mod, in the info section in admin). The only problem I am seeing is that the URLs are not using my SEO mod (still show as category.php?cat=whatever). I'm not sure if this affects anything, but it looks like it's doing it's job based on those reports.

    I am going to try your keyword tactics and report back next month.

    Thanks again
  15. crystal Customer

    Could you please explain how the use of headings (h1,h2) affects the page? I think I may be in violation of a search engine friendly site here... I am using h1 tags for all of the titles on my side boxes and I use h1 or h2 as the headers for the middle content. Is this something I have to change?

    Thanks again!
  16. jonahcoyote New Member

    I've heard that keeping all your headings in a line is a good idea, i.e. h1, h2, h3, and not h3, h1, h2 - keep them in order in your markup!

    Here is a quick guide on the do's and don'ts for headings: http://www.chaotic-neutrality.com/2008/05/22/seo-basics-how-to-use-heading-h1-h2-tags-properly/

    By the way, I have some code working that will only show the search results and heading on the search results page and not on say a owner listing. Here it is:

    Code:
    {assign var=Seller value=$smarty.get.owner}    
        {if $file=="searchresults.php" && !$Seller}
        <h3>Search Results</h3>
        <span style="font-style: italic;">You searched for: {$smarty.get.searchtext}</span>
        {elseif $file=="searchresults.php" && $Seller}
        <h3>Owner Listings</h3>
        {/if}
    It will only show the search results and heading if $Seller is not there.

    - Jonah
  17. seymourjames All Hands On Deck

    If you are using the SEF module and having problems generating sitemaps with your html URLs, I would advice you purchase a php sitemap generator and give google (open a google webmaster tools account) your sitemap.xml file. A good one for a small cost if you are on mac osx is igoomap. You can exclude certain pages so google does not get duplicate content (for example the php and html equivalent pages) and it will also follow the rules of your robots.txt file.

    Over H1 and H2 header tags there is good advice all over the internet and if memory serves me correctly on googles webmaster tolls pages themselves.
  18. crystal Customer

    Thanks Jonah! I didn't even realize the Search results text was showing up on my seller's listing page. I am using your code, it works great. I see that you were able to pull $Seller in with smarty. I tried using Listings by {$Seller} in my code, but it just returned the seller's number (i.e. Listings by 123). Is it possible to get the member name so it could say something like "Listings by membername"?

    I'm trying to figure out how to integrate the member profile with their listings. I'm hoping that I can make a single page with the seller details and all of their listings, so the user doesn't have to click twice.
  19. jonahcoyote New Member

    You're welcome Crystal,

    I was trying to do the same thing - pull in the owners name - but after futzing with it for about 30 mins decided to drop it.

    Anyone else have an idea of how to pull owners name into searchresults.php?

    Thanks,
    Jonah
  20. Lhotch curmudgeon

    The only thing related to the owner that is in the same DB tables as the ads is the owners ID. If you want any details from the owners table to be pulled and available to the searchlistings/viewlistings, you will need to modify the database query that is done via the underlying scripts and do a table join (like whats done in viewlisting.php) so that user and ad data is queried together.

    Then you would need to assign the additional values to template variables so they are usable in the templates.

Share This Page