We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Search Results not Linking Properly

How Do I?

TheLionsCher's avatar
TheLionsCher
46 posts
10 years ago
TheLionsCher's avatar TheLionsCher

Morning, folks! Having an issue with my search form results not linking to the results properly. Here’s the skinny:

Channel perferences for search are set to /site/search. Have template in my “site” template group called “search”. Results code looks like this. (All very basic, as I’m just implementing it all.)

{exp:search:search_results}
<a href="http://{auto_path}">{title}</a>
{/exp:search:search_results}

When I go to my website & search for something, I have no problem getting the right results for the search. The issue lies above, when I go to click on the link for one of the results, and receive a 404 error. The search results get pulled from the entries, naturally, but I’m not understanding WHY it’s not getting the link right. When I look at the URL in the browser, it has this structure:

http://www.mywebsite.com/site/search/10

Now, I will say this: I have 2 template groups for the site; 1 for all of the main stuff (home, faq, contact), and 1 for the shop, which is where all of the product templates are housed. Is this code expecting the search results to be found in my MAIN template group, and if so, how do I get it to point properly to the right entries? I’m completely at a loss at this point.

Many thanks, folks!

       
jay_turley's avatar
jay_turley
46 posts
10 years ago
jay_turley's avatar jay_turley

I don’t know if this is going to help, but here’s some info that may help you out:

First, the URL for where your search results should point is set on a per-channel basis. Access it by going to Admin -> Channel Administration -> Channels, then click on Edit Preferences for the channel for which you want to set the result URL.

For example, I have a FAQ page which shows all entries in the FAQ channel, but has no detail pages. Then I have the Projects page, which shows entries from the Projects channel, but has detailed pages to which we can link.

So, for the FAQ channel, I have the setting for the “Search Results URL” set to:

http://myexamplesite.com/faq/

And for the Projects channel, I have the setting for the “Search Results URL” set to:

http://myexamplesite.com/projects/detail/

But that wasn’t enough! The search results {auto_path} wants to link to detail pages by default. So I had to short-circuit the links with conditionals:

{exp:search:search_results switch="resultRowOne|resultRowTwo"}
    <tr class="{switch}">
        <td width="50%" valign="top">
            {if "{auto_path}" *= "about/faqs"}
                <strong><a href="http://{path=about/faqs}">{title}</a></strong>
            {if:else}
                <strong><a href="http://{auto_path}">{title}</a></strong>
            {/if}
    </td>
        <td width="50%" valign="top">{excerpt}</td>
    </tr>
{/exp:search:search_results}

Hopefully some combination of the above techniques will work out for you. If not, reply and we will see if we can go further.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.