• Hi everyone,

    The search results page for my website is terribly jumbled (search is currently disabled, because I am running an adwords campaign and can’t afford to have the unappealing search results displayed).

    I have been advised that I am missing a class of “post” on the search results page, but I have no clue how to fix that. Does anyone have suggestions on how I can fix this – or alternative code I can use – that will allow search results page to render normally?

    Here is the code from Search.php

    <?php get_header() ?>
    <div class="row">
    	<!-- content -->
    	<div id="content" class="column ninecol">
    		<?php if (have_posts()) : ?>
    			<?php switch_breadcrumbs(); ?>
    			<?php while (have_posts()) : the_post(); ?>
    				<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    				 <?php
    			        $format = get_post_format();
    			        if (false === $format) $format = 'standard';
    		        ?>
    				<?php get_template_part('content', $format); ?>
    				</article>
    			<?php endwhile; ?>
    			<?php switch_content_nav(); ?>
    		<?php else : ?>
    			<article id="post-0" <?php post_class() ?>>
    				<header>
    					<h1 class="entry-title"><?php _e('Nothing Found', 'switch'); ?></h1>
    				</header>
    				<div class="entry-content">
    					<p><?php _e('Sorry, but no entries matched your search criteria. Please make sure all words are spelled correctly or try again with some different keywords.', 'switch' ); ?></p>
    				</div>
    			</article>
    		<?php endif; ?>
    	</div>
    	<!-- /content -->
    	<?php get_sidebar() ?>
    </div><!-- /row -->
    <?php get_footer() ?>
Viewing 6 replies - 1 through 6 (of 6 total)
  • The code seems okay. A link to the actual search result page would really help.

    Thread Starter SkyWayne

    (@skywayne)

    Thank you so much for your response.

    Here is an example of a search results page with jumbled results:

    https://www.mwpatton.com/?s=Homestead+exemption

    It would really be great if search results were displayed in short snippets. Not sure how to make that happen, but it would be wonderful.

    I see the problem. Your search query returns posts AND pages. It’s the page that makes the layout break since its using a page class instead of post like the rest.

    You can either edit the CSS of the page class to match it with post class OR exclude pages from the search result.

    About the results displaying snippets, you should swap the_content() with the_excerpt() on the template page.

    Thread Starter SkyWayne

    (@skywayne)

    Thank you so much, Andi. I’m very excited now . . . just two more things:

    How do I edit the files so that pages are not included in search results?

    I have no idea how to do that! ??

    On the excerpt issue, which template page? My theme has the following .php files:

    404 Template
    Main Index Template
    Page Template (page.php)
    Full Width Page Template
    Homepage Template
    Snippets Page Template
    Testimonials Page Template

    Page.php has this code (and I assume you would want me to change the first instance of the_content (), is that correct?:

    <?php get_header() ?>
    
    <div class="row">
    
    	<!-- content -->
    	<div id="content" class="column ninecol">
    
    		<?php switch_breadcrumbs(); ?>
    
    		<?php while ( have_posts() ) : the_post(); ?>
    
    			<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    				<header>
    					<h1 class="entry-title"><?php the_title(); ?></h1>
    				</header>
    				<div class="entry-content">
    					<?php the_content(); ?>
    					<?php wp_link_pages(array( 'before' => '<div class="page-link"><span>' . __( 'Pages:', 'switch' ) . '</span>', 'after' => '</div>' ) ); ?>
    				</div>
    			</article>
    
    		<?php endwhile; // end of the loop. ?>
    
    		<?php switch_content_nav(); ?>
    
    	</div>
    	<!-- /content -->
    
    	<?php get_template_part('sidebar', 'page'); ?>
    
    </div><!-- /row -->	
    
    <?php get_footer() ?>
    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

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