• Hello!

    I’ve created my own theme on https://erikalundell.com/axel/. I have problems with the search result page on bigger sized screens.

    The result code sits within the section #main. This element has a negative margin of -9em. The section element is opened in the “header.php”-file, so this couldn’t be a CSS issue.

    When there are at least 1 result found, there are no problems at all. It shows as expected. However, when 0 results were found, the “Search Results” page is pushed down.

    Working search result:
    https://erikalundell.com/axel/?s=about

    Not working:
    https://erikalundell.com/axel/?s=ggg

    The search.php file looks like this:

    <?php get_header(); ?>
    
    <?php if ( !(have_posts()) ) : 
    
    	echo '<h2 class="page-title not-found">Search results</h2>
    		<p>Sorry, no posts matched your search criteria.</p>';
    
    else : ?>
    
    	<h2 class="page-title search">Search results</h2>	
    
    	<p><?php
    	global $wp_query;
    	$total_results = $wp_query->found_posts;
    	echo $total_results;
    
    	if ($total_results!= 1) :
    		echo ' posts found.';					
    
    	else :
    		echo ' post found.';
    
    	endif;
    
    	?></p>
    
    	<?php while ( have_posts() ) : the_post(); ?>
    
    		<article <?php post_class('search-result'); ?> id="post-<?php the_ID(); ?>">
    			<h3 class="entry-title"><?php the_title(); ?></h3>
    			<div class="entry-content"><?php the_content(); ?></div>
    			<p class="entry-meta">
    
    			<span class="date">Posted <?php the_date(); ?> </span>
    
    			<span class="tags"><?php the_tags('Tagged as '); ?></span>
    
    			<?php if ( count( get_the_category() ) ) : ?>
    				<span class="cat-links">
    				Categories: <?php echo get_the_category_list( ', ' ); ?>
    				</span>
    			<?php endif; ?>
    			</p>
    		</article>
    
    	<?php endwhile ; ?>				
    
    <?php endif; ?>
    
    </section>
    </div>
    
    </div>
    
    <?php get_footer(); ?>

    I tried working around this with using a negative margin on the h2 element, but nothing happened apart from pushing down section#content. Also tried using the body class to add more negative margin to section#content, didn’t work either.

    Can’t figure out why this isn’t working – I can’t see any unrelated CSS with FireBug, nor any generated content that shouldn’t be there…

    Thanks in advance!

    //Erika

  • The topic ‘Search Results pushed down on page, but only when no results were found’ is closed to new replies.