我有一个非常简单的loop对于网站上的存档页面:
<?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(); ?>
这是 no-results
模板完整:
<h2>Nothing here yet.</h2>
<p>Please <a href="<?php bloginfo('url'); ?>/">return to the home page</a>.</p>
由于存档当前为空,no-results.php
的内容正如预期的那样显示。浏览一下页面源代码,<h2>
之间没有任何内容(甚至没有空格)。及其包含 <div>
,但是<h2>
在页面上向下推一行,开发者控制台在其上方显示一个空文本节点:
马虎的空白是一回事;实际上影响我的布局的空白是另一个。我是否遗漏了什么可能导致此问题?
最佳答案
您是否有机会使用记事本创建无结果
模板?
我猜你的模板以 UTF-8 Byte order mark 开头。当您使用 UTF-8 编码保存文件时,记事本会默认插入它。其他一些文本编辑器也可以这样做,但通常有一个选项可以将其关闭。
使用不插入 BOM 的编辑器,或者考虑到您的模板不包含任何非 ASCII 字符,只需将其另存为 ASCII/ANSI。
关于php - 为什么 PHP/WordPress 在这里回显空行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8020606/