Customizing search results page for use with Relevanssi

Community Forums Forums Design Tips and Tricks Customizing search results page for use with Relevanssi

This topic is: resolved

This topic contains 24 replies, has 3 voices, and was last updated by  Guter 1 year, 6 months ago.

Viewing 15 posts - 1 through 15 (of 25 total)
  • Author
    Posts
  • #8384

    lostintime
    Participant
    Post count: 55

    To make searching a better user experience I am using the plugin Relevanssi on my blog. Now I would like to implement Google-style “did you mean” suggestions for those situations where no results are found. The plugin author suggests adding the following line of code to the search results page in order to get that extra functionality:

    <?php if (function_exists('relevanssi_didyoumean')) { relevanssi_didyoumean(get_search_query(), "Did you mean: ", "", 5); }?>

    My question is: Where exactly should this piece of code go and how do I go about adding it? My theme (Streamline) does not have its own search.php file and search.php under genesis/lib/functions/ seems to deal only with the search form, not with the results page.

    Any help is greatly appreciated.

    • This topic was modified 1 year, 7 months ago by  lostintime.
    • This topic was modified 1 year, 7 months ago by  lostintime.
    • This topic was modified 1 year, 7 months ago by  lostintime.
    • This topic was modified 1 year, 7 months ago by  lostintime.
    • This topic was modified 1 year, 7 months ago by  lostintime.
    • This topic was modified 1 year, 7 months ago by  lostintime.
    #8402

    Bill Murray
    Participant
    Post count: 575

    You can add the code in the attached link to your child theme’s functions.php.  See the inline documentation in the code to add it just to your search page.  To do that, get the page ID of your search results page (you can mouse over the URL in the WP dashboard and note the ID in the URL) and replace ’1234′ with your page ID.

    http://wpp.im/9

    Always be sure to have a good backup of your functions.php and the ability to put back a good copy to your server (such as with FTP) prior to making any changes, because even a small typo can break your site.


    Web: https://wpperform.com or Twitter: @wpperform

    We do managed WordPress hosting.

    #8428

    lostintime
    Participant
    Post count: 55

    That looks great Bill. Thanks! Will try it and let you know how it goes.

    Just a thought: Could I replace

    if ( is_page(’1234′) ) {

    with

    if ( is_search() ) {

    ?

    #8454

    Bill Murray
    Participant
    Post count: 575

    Good thought. That change should work too. Give them both a try and post back with your results.


    Web: https://wpperform.com or Twitter: @wpperform

    We do managed WordPress hosting.

    #8615

    lostintime
    Participant
    Post count: 55

    It works – you’re brilliant Bill :-)

    Now I only have to figure out how to style the output, because the resulting string gets displayed at the top left corner of the browser window instead of *inside” the search results page, where I want it to appear.

    Any suggestions on that?

    Happy New Year’s Eve!

    #8620

    Bill Murray
    Participant
    Post count: 575

    Please up your standards for brilliance. :)

    Have a link to your site? I can check what CSS Relevannsi is outputing with its function, which is quicker than looking in the code.

    Btw, did the is_search() work?

    Same to you.


    Web: https://wpperform.com or Twitter: @wpperform

    We do managed WordPress hosting.

    #8623

    lostintime
    Participant
    Post count: 55

    Yes, is_search() worked fine, which makes the function a bit more generic.

    Here’s the link to my site: http://www.buurtaal.de/blog/

    It’s in German. I hope that doesn’t scare you ;-) The search box is in the sidebar, there where it says “SUCHEN AUF BUURTAAL”

    I used the search term “olibollen” . That should give you “Did you mean: oliebollen” in the left top corner. (The free version of Relevanssi which I am using bases the suggestions on logged queries. Since I only started usin the plugin yesterday there is currently very little data.)

    Thanks again for your help, it’s very much appreciated.

    #8639

    Bill Murray
    Participant
    Post count: 575

    I took a look and updated the code on my link. Grab an updated copy and it should fix the problem you observed.

    The bad placement was because I wasn’t sure where that function would do its work, so I loaded it in a less than ideal place. I’ve now set it to load in a more ideal place, but we’ll have to see if the change suits your needs.

    Post back with the results.


    Web: https://wpperform.com or Twitter: @wpperform

    We do managed WordPress hosting.

    #8698

    lostintime
    Participant
    Post count: 55

    You’re my coding hero Bill ;-)

    I ended up changing the hook to genesis_after_content because using genesis_before_content displayed the result in the sidebar.

    Thank you so much for pointing me in the right direction.

    #8722

    Bill Murray
    Participant
    Post count: 575

    Hmmm…after thinking about this more, the genesis_after_post_content hook might be even better. genesis_after_content isn’t quite right, which is why the text is so far to the left.


    Web: https://wpperform.com or Twitter: @wpperform

    We do managed WordPress hosting.

    #8725

    lostintime
    Participant
    Post count: 55

    I tried that, but unfortunately genesis_after_post_content made the string disappear …. Could that be because the search results are not displayed in a post?

    Using genesis_after_content seems to bring the best result – even though it isn’t pretty because of the missing left margin.

    Would it be possible to style the output using css? Or would you consider that a hack?

    #8734

    Bill Murray
    Participant
    Post count: 575

    Before we go the CSS route, let’s try this:

    add_action(‘genesis_after_post_content’, ‘wpp_relevanssi_did_you_mean’, 5);


    Web: https://wpperform.com or Twitter: @wpperform

    We do managed WordPress hosting.

    #8736

    lostintime
    Participant
    Post count: 55

    Bummer, no joy unfortunately. The string doesn’t display anywhere on the page.

    #8737

    Bill Murray
    Participant
    Post count: 575

    Let’s not give up yet…

    Does Relevanssi create a page for search results? Can you try the code in my last example using the is_page() with the page ID? I’m wondering if the is_search() thing is breaking it.

    The addition of the priority (the 5 parameter) should have fixed the “not displaying” issue.


    Web: https://wpperform.com or Twitter: @wpperform

    We do managed WordPress hosting.

    #8764

    lostintime
    Participant
    Post count: 55

    The thing is that I there doesn’t seem to be a separate page for displaying the search results. At least there’s nothing in the Streamline backend. That’s what’s preventing me from using is_page() with the page ID.

Viewing 15 posts - 1 through 15 (of 25 total)

The topic ‘Customizing search results page for use with Relevanssi’ is closed to new replies.