• I would like another search results page and am not sure how to implement this.

    I want one search results page that comes up when there is a positive result. That page is perfect right now.

    But when there is a negative result (nothing found) I would like a different result to come up. I want to remove the social media icons from my header and the search box from my header to clean up the page.

    Who is going to “like” a “no results found” page and also, there is no reason to have two search boxes–one in the header and one in the body of the page.

    Any ideas on how to implement this?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Moderator t-p

    (@t-p)

    Thread Starter dannydanny

    (@dannydanny)

    Thanks for this but it’s not quite what I’m looking for.

    I know how to create the search results page that I want. That is, to delete the search bar and the social media icons from the header. I can simply use the original twenty twelve theme header in search.php and put that file in my child theme and I’m done.

    Then, when someone does a search and it comes up as “nothing found,” my page is perfect. No social media icons, no search bar up top, the search bar right there after the “not found” message so the user can do another search . . . it looks perfect!

    BUT . . . when someone does a search and finds say, two results that are wrong and wants to do another search, there is no search bar at the top OR the bottom. That’s not good.

    So I need two search results pages. I know how to make them both. I just don’t know how to make the site search call one of them when there’s a positive result and the search call the other one when there are no results found.

    Moderator bcworkz

    (@bcworkz)

    No need for two pages. Put all the content for both conditions on the same template page. Use the same if ( have_posts() ) : conditional as used in the main loop to control which elements are output when there are posts and which to output when there are not.

    If you really want two pages, hook the ‘search_template’ filter. Check the number of posts from the global query object $wp_query. Return the appropriate template path.

    Thread Starter dannydanny

    (@dannydanny)

    No need for two pages. Put all the content for both conditions on the same template page. Use the same if ( have_posts() ) : conditional as used in the main loop to control which elements are output when there are posts and which to output when there are not.

    You know, I’m sure this is what I’m looking for. But what you just said is all Greek to me. I understand the first part (I think). I paste the entire page and paste it again in the same document. One below the other. Right?

    But after that I have no idea what you’re saying. Use the same if ( have_posts() ) : conditional — huh? As a php know-nothing, I have no clue what this means. What page do I have to edit to use the same if ( have_posts() ) : conditional? And how do I use the same if ( have_posts() ) : conditional?

    I’m sorry. I just don’t know! I’m a teacher myself and I have a few videos on how to make WordPress websites. I explain everything step-by-step figuring people aren’t going to have a clue what I’m talking about most of the time.

    And for php, I need step-by-step details. If you’d be willing to provide those step-by-step details for me (assuming I know nothing about php or which files to edit or anything) I would be MOST grateful.

    Moderator bcworkz

    (@bcworkz)

    Here’s the basic framework for a results page that does one thing when there are posts and something else if not. You can see some common elements occur for both conditions– head, sidebar, footer, that are outside the conditional structure. How templates like this work is theme dependent, this template is typical for most themes, but your theme may require modifications to work properly. To start with, just insert your HTML content where indicated, and see how that goes.

    <!-- common head section content goes here -->
    <?php if ( have_posts() ) : ?>
       <!-- HTML content appropriate for results found goes here -->
       <?php while ( have_posts() ) : the_post();
          // This "The Loop" where search results are output
          get_template_part( 'content', get_post_format() );
       endwhile; ?>
    <?php else : ?>
       <!-- HTML content appropriate for results not found goes here -->
    <?php endif; ?>
    <!-- More common HTML can go here -->
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Customizing Search Results Page’ is closed to new replies.