WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] Creating a Custom Search Results Page?

[Resolved] Creating a Custom Search Results Page?

  • WPChina

    @wordpresschina

    I have searched far and wide for the answer to this question.

    I need to customize my search results page based on certain search terms.

    For example, if s=Apple, I need to place a certain image at the top of the results.

    If s=Orange, I need to include some text and a PHP include.

    Is there simple code to place within the Loop to do this? Or can I do it outside the Loop and base it on the search term?

    Tks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • esmi

    @esmi

    Forum Moderator

    I’ve not tested this but what about:

    <?php
    if( trim( wp_specialchars($s,1) ) == 'Apple' ) :?>
    	[ add image markup here ]
    <?php elseif( trim( wp_specialchars($s,1) ) == 'Orange' ) :?>
    	[ add text with markup here ]
    	<?php include ('somefile.php');
    endif;?>

    just before the Loop in search.php?

    WPChina

    @wordpresschina

    @esmi: Excellent 🙂 it works!
    Many thanks and I hope to return the favor to you soon for support!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Resolved] Creating a Custom Search Results Page?’ is closed to new replies.