Thanks for visiting! This is the weblog of Lynda, a 26 year old girl living in Atlanta with her husband, three cats and two cockatiels.
| Home | Journal | Photos | Contact |
I got this idea from a thread on the forum. I recently added “Most Recent Searches” performed by other people on my Search Page and I might even add it to the sidebar. It’s quite simple to do with the wonderfully powerful query module in EE.
Here’s the code I’m using:
Simple, isn’t it? This will link to the actual search. You can change your path if needed and the limit for how many searches you’d like to pull up. You can add the date, but that would require some PHP to decode the timestamp.
Additionally, you can include member information if you wish, however this will only pull up results that MEMBERS have searched for, not guests!
Thanks for that. I had been playing around with adding that back to my site, but your solution was so much better and usabable than mine.
Is it normal that when a new search is performed the last search info is erased? that seemed to happen when I first put it up, but I don’t know if it will replicate it now. (this is a great plugin - thanks
)
If you’re limiting your results, then the last search will be erased when a new search is performed. If you’re not limiting your results, this shouldn’t happen. I’m not sure how many searches EE is set to keep, but if it only keeps a certain number (say 20) then the oldest will be removed also.
{exp:query sql="SELECT * FROM ee_search order by search_date desc limit 10"}
<a href="{path=search/results}{search_id}">{keywords}</a> ( {total_results} result<? $results = "{total_results}"; if ($results != "1") { ?>s<? } ?> )<br />
{/exp:query}
Works for displaying the correct form of the word result (ie ‘1 result’ or ‘6 results’
. Thanks for the start of the code, Lynda.
I am using this but altering the “limit 10” has no effect. With or without it and irrespective of it’s value, only a single search term is returned. Any thoughts what I am doing wrong?
It’s quite possible only one search term is available. Try doing some searches to see if additional results show up. EE only keeps the search results for a limited time I believe, although I’m not sure how long that period of time is. So you might not always have the full results available to display.
You don’t need PHP in order to render the timestamp. You can do it in SQL.