0

I'm setting up a search feature on a site and one of the channels that it's searching is downloads. Rather than link all download results to the downloads page using the {auto_path} tag and then expect the user to find the download they want, I'd like to create a link which will actually download the file from the search results page.

The issue is that when trying to do this, subsequent results seem to have incorrect links, as if the search module is getting confused?

Here's my code, any thoughts or alternative ways to achieve this are massively appreciated!

Thanks in advance,

Tom

{exp:search:search_results}
<div class="col span_1_of_1 search_results">
    <div class="padding">
        <h3 class="no_margin_bottom">
            {if channel == 'Downloads'}
                {if download_file != ''}
                    <a href="{download_file}">{title}</a>
                {if:elseif download_link != ''}
                    <a href="{download_link}">{title}</a>
                {/if}
            {if:else}
                <a href="{auto_path}">{title}</a>
            {/if}
        </h3>
        <p class="subtitle extra_margin_bottom">{entry_date format="%j%S %F %Y"}</p>
        <span class="label">{channel}</span>
        <p>{excerpt}</p>
        {if channel == 'Downloads'}
            {if download_file != ''}
                <a href="{download_file}" download target="_blank" >Download</a>
            {if:elseif download_link != ''}
                <a href="{download_link}" download target="_blank" >Click to download</a>
            {/if}
        {if:else}
            <a href="{auto_path}">Read more</a>
        {/if}
    </div>
</div>
{/exp:search:search_results}
0

Maybe try simplifying by getting rid of the nested if:elses?

eg

{if download_file != ''} <a href="{download_file}">{title}</a>{/if} {if download_link != ''} <a href="{download_link}">{title}</a> {/if}

(Assuming both fields won't be populated of course.)

2
  • Thanks for your suggestion Zack, it's still linking strangely I'm afraid. The first case study result links correctly, as do the second and third download results. It's from the fourth result (which is a news story) that uses incorrect links. It actually uses the links from the second result which is a download. Maybe the conditionals in search results are causing the problem but I don't know how to achieve it any other way? Apr 14 '15 at 6:43
  • Managed to crack it (see below). Thanks for your help. Apr 14 '15 at 6:56
0

I've managed to solve this by removing the complex conditionals, including all links and then simply hiding the links I don't want to appear using CSS. This is a bit of a workaround I know but in this case seemed to be the best solution.

Here's a copy of my code and CSS.

HTML:

{exp:search:search_results}
    <div class="col span_1_of_1 search_results {if channel == 'Downloads'}download{/if}">
        <div class="padding">
            <h3 class="no_margin_bottom">
                <a class="auto_path" href="{auto_path}">{title}</a>
                {if download_file != ''}<a href="{download_file}" download target="_blank" >{title}</a>{/if}
                {if download_link != ''}<a href="{download_link}" download target="_blank" >{title}</a>{/if}
            </h3>
            <p class="subtitle extra_margin_bottom">{entry_date format="%j%S %F %Y"}</p>
            <span class="label">{channel}</span>
            <p>{excerpt}</p>
            <p><a class="auto_path" href="{auto_path}">Read more</a>
                {if download_file != ''}<a href="{download_file}" download target="_blank" >Click to download</a>{/if}
                {if download_link != ''}<a href="{download_link}" download target="_blank" >Click to download</a>{/if}
            </p>
        </div>
    </div>
{/exp:search:search_results}

CSS:

.download .auto_path {
    display: none;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.