0

I want to display up to 200 words of the related results just in the next line to title But i am not getting the text that {excerpt} should Display

My code is written below

{exp:search:search_results switch="resultRowOne|resultRowTwo"}


<table border="0" cellpadding="6" cellspacing="1" width="100%">

{exp:search:search_results switch="resultRowOne|resultRowTwo"}

    <tr class="{switch}">
   {if page_meta_title != ""} <td width="30%" valign="top"><b><a href="{if page_meta_resource}{page_meta_resource}{if:elseif page_meta_override_url}{page_meta_override_url}{if:else}/{title_permalink}{/if}">{title}</a></b></td>{/if}    
</tr>
<tr><td style="color:red!important">{excerpt}</td></tr>
    {if count == total_results}
        </table>
    {/if}

    {paginate}
        <p>Page {current_page} of {total_pages} pages {pagination_links}</p>
    {/paginate}

{/exp:search:search_results}

</table>
1
  • In your code, you appear to have 2 opening {exp:search:search_results} tags. Is this indeed the case? If so, remove the top one. – Low Jan 31 '14 at 13:16
2

The {excerpt} variable, which is defined in the Channel Preferences, consists of the first 50 words from the field specified (see docs). If you need more than that, you're probably better off using the regular custom field notation and using something like Hacksaw or TruncHTML to limit that field to 200 words.

To make sure the {excerpt} is defined correctly:

  • Go to CP > Admin > Channel administration > Channels;
  • Go to Edit Preferences for a channel;
  • Under Administrative Preferences, make sure Which field should be used for search excerpt? points to the correct field (only fields that have been set as “searchable” will be included);
  • Repeat for each relevant channel.
8
  • Low!! as you see in my code i have already used {excerpt}..But i am not getting the text – user2576 Jan 31 '14 at 11:04
  • Make sure it's correctly defined in the Channel Preferences: ellislab.com/expressionengine/user-guide/cp/admin/channels/… – Low Jan 31 '14 at 11:09
  • Can you give me some hint? – user2576 Jan 31 '14 at 11:12
  • I thought I did with that link. Updated my answer with a step by step walkthrough. – Low Jan 31 '14 at 11:22
  • I got an option called Which field should be used for search excerpt? Under Administrative Preferences But i am just getting Blog Body in a drop down next to it – user2576 Jan 31 '14 at 11:22
0

As Low has already said, you need to set the field as searchable.

To do that, go to the Channel Field that you want to use as the excerpt and set Is field searchable? to Yes.

Then go back to the Channel preferences and you should now be able to select that field in the Which field should be used for search excerpt? dropdown.

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.