我在使用html标记包装输出内容时出现问题。
我写这个..
<p class='pWrap'>
<?php the_content(); ?>
</p>
得到这个..
<p class='pWrap'>
</p>
<p>Content</p>
我也试着这样写..
<?php echo "<p class='pWrap'>" ?>
<?php the_content(); ?>
<?php echo "</p>" ?>
但结果相同。
为什么会这样?
总代码部分看起来像这样..
<article>
<?php query_posts('posts_per_page=8'); ?>
<?php if (have_posts()) : ?><?php while (have_posts()) : the_post(); ?>
<li>
<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a>
<p class='pWrap'>
<?php the_content(); ?>
</p>
</li>
<?php endwhile; ?>
<?php endif; ?>
答案 0 :(得分:0)
问题是嵌套<p>
元素是非法的。
如果您致电the_content()
,Wordpress会自动将内容包装在一个段落中。要避免这种情况,请删除以下过滤器:
remove_filter( 'the_content', 'wpautop' );
或者我建议您使用div
代替段落来包装内容。