Have a better way to display image in search result?
Hi Low and everybody!
I get a trouble when want to display image in result page.
As example, I have 3 channels with have structure like:
Channel 1 (ch_1):
- Title: title
- Anchor image: ch_1_image
Channel 2 (ch_2):
- Title: title
- Anchor image: ch_2_image
Channel 3 (ch_3):
- Title: title
- Anchor image: ch_3_image
So, in search result page I can list result:
{exp:low_search:results query="{segment_2}"}
<h1>{title}</h1>
{if channel_short_name == ch_1}<img src="{ch_1_image}" />
{/if}
{if channel_short_name == ch_2}<img src="{ch_2_image}" />
{/if}
{if channel_short_name == ch_3}<img src="{ch_3_image}" />
{/if}
<a href="{comment_url_title_auto_path}">more...</a>
{/exp:low_search:results}
As you see, I have to repeat multi times + check to return right image. But I have not to do this with {title} and {comment_url_title_auto_path}.
Have anyone get a better solution?
Thank all!
Replies
Low 2 Apr 2014 16:19
I'm afraid the way you set it up is the way to do it. As long as you're not sharing fields, this is the way you display fields from multiple channels.
Things like Title and Entry Date are general fields, available in all channels. But custom fields can differ on a per-channel basis, so you'd have to use conditionals to display the right ones.
ngoncom 3 Apr 2014 10:29
Thank you so much, I appreciate your help!