Search excerpts instead of content

Community Forums Forums Design Tips and Tricks Search excerpts instead of content

This topic is: not resolved

This topic contains 3 replies, has 4 voices, and was last updated by  robertbiswas 5 months, 2 weeks ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #95959

    Jummul
    Participant
    Post count: 40

    I want search results to show excerpts instead of content. My current search.php from my child theme shows this:

    
    <?php
    /**
     * Genesis Framework.
     *
     * WARNING: This file is part of the core Genesis Framework. DO NOT edit this file under any circumstances.
     * Please do all modifications in the form of a child theme.
     *
     * @package Genesis\Templates
     * @author  StudioPress
     * @license GPL-2.0+
     * @link    http://my.studiopress.com/themes/genesis/
     */
    
    add_action( 'genesis_before_loop', 'genesis_do_search_title' );
    
    /**
     * Echo the title with the search term.
     *
     * @since 1.9.0
     */
    function genesis_do_search_title() {
    
    	$title = sprintf( '<div class="archive-description"><h1 class="archive-title">%s %s</h1></div>', apply_filters( 'genesis_search_title_text', __( 'Search Results for:', 'genesis' ) ), get_search_query() );
    
    	echo apply_filters( 'genesis_search_title_output', $title ) . "\n";
    
    }
    
    genesis();
    http://www.acupoflife.nl
    #96127

    Tom
    Participant
    Post count: 892

    Put that file away, open up functions.php.

    https://gist.github.com/srikat/6912382
    courtesy Sridhar Katakam


    Choose your next site design from over 350 Genesis themes.
    Updates via GenesisThemes.ca | Twitter | Google+ | Tumblr

    #96180

    Summer
    Participant
    Post count: 1092

    Actually, from a cleaner coding perspective you’d want to create a search.php instead of cluttering up functions.php. Custom templates are your friend :)

    All you’d need to do is add this to a custom search.php:

    add_filter( 'genesis_pre_get_option_content_archive', 'sk_show_excerpts' );
    function sk_show_excerpts() {
        return 'excerpts';
    }

    You might also want to play around with which image to display, or display none at all, but that way the code is only called when a visitor does a search, and never anytime else.


    #99406

    robertbiswas
    Member
    Post count: 1

    Thanks Tom, The hook works great on my genesis child theme. I’m wondering how to add a “read more” link after every excerpt though it’s works fine with the title.
    Thanks again

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.