• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

Custom search.php

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password

Community Forums › Forums › Archived Forums › Design Tips and Tricks › Custom search.php

This topic is: resolved

Tagged: relevanssi, search, search.php

  • This topic has 7 replies, 2 voices, and was last updated 11 years, 4 months ago by cookieandkate.
Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • March 9, 2014 at 11:26 pm #94126
    cookieandkate
    Member

    Hi,

    I'm really frustrated because I can hardly find any documentation on how to customize Genesis search results (this forum post only tells me how to remove post details from search results). I'm using Magazine Pro, which, by default, displays full posts in the search results. I want to show post excerpts instead, but changing the Genesis theme option to display excerpts throughout the site is not an option.

    What I want in a search results page:
    Post title
    Post excerpt (called by the_excerpt, not the_content, so that Relevanssi works)
    More link

    I want to be able to specify the number of search results that display on the page. My default archive setting is to display six, but I want eighteen search results per page.

    Can anyone help me with this? I would be so thankful.

    Kate

    March 11, 2014 at 4:22 am #94249
    Wordpress
    Member

    This assumes HTML5 is enabled. Place this in your functions.php file:

    // Set number of posts for search results to 18
    add_action( 'pre_get_posts', 'child_search_posts_per_page' );
    function child_search_posts_per_page( $query ) {
        if ( !is_admin() && $query->is_main_query() && $query->is_search() ) {
            $query->set( 'posts_per_page', 18 );
        }
    }

    Now copysearch.php from Genesis parent theme (if you haven't already), and paste it into your Child template directory. In that search.php file put in the following code (right before the genesis();) Like so:

    // Remove post info & entry footer - Optional
    remove_action( 'genesis_entry_header', 'genesis_post_info', 12 );
    remove_all_actions( 'genesis_entry_footer' );
    
    // Excerpt and "read more" link
    remove_all_actions( 'genesis_entry_content' );
    add_action( 'genesis_entry_content', 'child_do_post_excerpt' );
    function child_do_post_excerpt() {
        the_excerpt();
        echo '<a class="read-more-link" href="' . esc_url( get_permalink() ) . '">read more</a>';
    }
    
    genesis();

    Note: I haven't tested with the Relevanssi plugin.

    March 11, 2014 at 10:43 am #94290
    cookieandkate
    Member

    That code works great. Thank you! Thank you so much.

    Notes: I decided that I wanted the date and comments link to display, so I deleted that line. I found that deleting remove_all_actions( 'genesis_entry_footer' ); made Relevanssi stop working.

    Lastly, I'm sorry, I forgot to mention that I would like for the post thumbnail to display under the title, with the post excerpt to the right of it. I tried adding the_post_thumbnail('thumbnail'); above the_excerpt, but nothing happened. My post thumbnail size under media settings (which is the thumbnail I would like to display) is 130x179 px.

    Desired final result would look like my archive pages.

    If you know how to display the thumbnail, I would be tremendously thankful if you could share the code.

    Thank you!
    Kate

    March 11, 2014 at 10:49 am #94291
    cookieandkate
    Member

    Actually, strangely enough, the_post_thumbnail('thumbnail'); does produce thumbnails in the search results. However, it doesn't produce a thumbnail next to each of my posts, only one here and there, which doesn't make sense because I have set a featured image for each post. Another problem is that the thumbnails don't include the "alignleft" class that they need in order to display the excerpt to the right, rather than underneath. Lastly, Relevanssi isn't working.

    I know that it must be possible to display the thumbnail next to the excerpt because that is how I had my search results set up on my former design.

    March 11, 2014 at 10:57 am #94292
    cookieandkate
    Member

    Victory!!! I figured it out by consulting the codex. The reason thumbnails weren't displaying next to all of the posts is because I'm testing the code on my test site and I haven't set thumbnails for all of the test site's posts.

    Final code:

    <?php
    
    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";
    
    }
    
    // Remove post info & entry footer - Optional
    remove_all_actions( 'genesis_entry_footer' );
    
    // Excerpt and "read more" link
    remove_all_actions( 'genesis_entry_content' );
    add_action( 'genesis_entry_content', 'child_do_post_excerpt' );
    function child_do_post_excerpt() {
    the_post_thumbnail('thumbnail', array('class' => 'alignleft'));
        the_excerpt();
        echo '<a class="read-more-link" href="' . esc_url( get_permalink() ) . '">Continue reading ยป</a>';
    }
    
    genesis();
    
    March 11, 2014 at 7:19 pm #94346
    Wordpress
    Member

    ^ Looks good. That's done.

    As for the plugin, I've tried and it works. I can see search terms highlighted. Adding/removing code didn't affect it. I can only suggest the obvious like reinstalling the plugin or rebuilding the index. Not much else I can do there sorry.

    March 11, 2014 at 7:57 pm #94358
    cookieandkate
    Member

    Sorry for the confusion. The plugin is working great with the code I provided above.

    March 11, 2014 at 7:57 pm #94359
    cookieandkate
    Member

    P.s. Thanks again!

  • Author
    Posts
Viewing 8 posts - 1 through 8 (of 8 total)
  • The forum ‘Design Tips and Tricks’ is closed to new topics and replies.

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2025 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble