WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Creating a Custom Search Results Page? (3 posts)

  1. WPChina
    Member
    Posted 4 years ago #

    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!

  2. esmi
    Forum Moderator
    Posted 4 years ago #

    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?

  3. WPChina
    Member
    Posted 4 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic