HTML不会包装wordpress php the_content()

时间:2015-10-16 07:50:31

标签: php html wordpress

我在使用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; ?>

1 个答案:

答案 0 :(得分:0)

问题是嵌套<p>元素是非法的。 如果您致电the_content(),Wordpress会自动将内容包装在一个段落中。要避免这种情况,请删除以下过滤器:

remove_filter( 'the_content', 'wpautop' );

或者我建议您使用div代替段落来包装内容。

相关问题