I have a very simple loop for an archive page at a website:
<?php get_header(); ?>
<?php if(have_posts()): ?>
<div id="thumbs-container">
<?php while(have_posts()): the_post(); if(has_post_thumbnail()): ?>
<div <?php post_class('thumb'); ?>>
<a href="<?php the_permalink(); ?>">
<?php the_post_thumbnail('full',array('alt'=>get_the_title(),'title'=>null)); ?>
<div class="thumb-desc">
<h2><?php the_title(); ?></h2>
<p><?php echo get_post_meta($post->ID,'Description',true); ?></p>
</div>
</a>
</div>
<?php endif; endwhile; ?>
</div>
<?php else: get_template_part('no-results'); endif; ?> // <--problem here?
<?php get_footer(); ?>
And here is the no-results
template in its entirety:
<h2>Nothing here yet.</h2>
<p>Please <a href="<?php bloginfo('url'); ?>/">return to the home page</a>.</p>
Since the archive is currently empty, the contents of no-results.php
are shown, as expected. A glance at the page source shows nothing (not even white space) between the <h2>
and its containing <div>
, however the <h2>
is pushed down one line on the page and the Developer Console shows me an empty text node above it:
Sloppy whitespace is one thing; whitespace that actually affects my layout is another. Is there something I’m missing which might be causing this?
Did you by any chance use Notepad to create your
no-results
template?I would guess that your template starts with a UTF-8 Byte order mark. Notepad inserts it by default when you save a file with the UTF-8 encoding. Some other text editors also do that, but usually have an option to turn it off.
Use an editor that doesn’t insert a BOM, or, considering your template doesn’t contain any non-ASCII characters anyway, simply save it as ASCII/ANSI.
Seems like you are close thing if before the while loop?
<?php endif; endwhile; ?>
Seems wrong because you open the if fist and the while second so you should close them in most recent first order e.g.<?php endwhile; endif; ?>
i think you should move the closing tag wich screwed your markup