2015-10-16 28 views
0

我有一個問題包裝與html標籤outputed內容。HTML不會包裝wordpress php the_content()

我寫這個..

<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

你可以檢查沒有包裝'html'?只是爲了確保你的while循環正在工作。 –

+0

無論我是否嘗試包裝它,都會顯示所有帖子的內容。 –

+0

嗯,那麼你可以試試@xphan的答案。 –

回答

0

的問題是,嵌套<p>元素是非法的。 如果你打電話the_content() WordPress的自動包裝的段落內容。爲了避免這種情況,刪除以下過濾器:

remove_filter('the_content', 'wpautop'); 

另外我建議你使用div,而不是一個段落換行的內容。

+0

謝謝xphan,我不知道這個WordPress的規則。我已將p標籤更改爲div標籤,並且按預期工作。 –