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