wordpress調用the_excerpt()不帶

標簽


  我們知道wordpress調用摘要內容用<?php the_excerpt(); ?>就可以,但是它會自動添加一個p標簽,例如<p>這里是description</p>,如果我們不想要這個p怎么處理呢?其實很簡單,用下面的代碼就能實現

<?php echo get_the_excerpt(); ?>

  同樣的道理,如果想調用內容不帶p標簽,可以用

<?php echo get_the_content(); ?>

  另外一種方法去掉p標簽是在你的主題function.php中定義

remove_filter (  'the_excerpt' ,  'wpautop'  );
remove_filter (  'the_content' ,  'wpautop'  );

  你一定會喜歡這篇文章

wordpress去掉摘要p標簽的完美解決方案

  或者用下面的方法截取文章多個詞

<?php $excerpt = wp_trim_words(get_post_field('post_content', $post_id), 16); echo $excerpt; ?>

  或

<?php 
$trimexcerpt = get_the_content();
$shortexcerpt = wp_trim_words( $trimexcerpt, $num_words = 18, $more = '… ' ); 
echo $shortexcerpt;
?>

  或者

<?php
echo mb_strimwidth(strip_tags(apply_filters('the_content', $post->post_content)), 0, 170,"……");
?>

  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM