内容字数做为摘要

Posted ytkah

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了内容字数做为摘要相关的知识,希望对你有一定的参考价值。

以下是调用指定分类文章列表的一个方法,作者如果有填写文章摘要则直接调用摘要;如果文章摘要忘记写了则自动截取文章内容字数做为摘要。这个方法也适用于调用description标签

<ul>
<?php
    $args=array(
        ‘cat‘ => 1,   // 分类ID
        ‘posts_per_page‘ => 10, // 显示篇数
    );
    query_posts($args);
    if(have_posts()) : while (have_posts()) : the_post();
?>
    <li>
        <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> //标题
        <p>
        <?php if (has_excerpt()) 
                echo $description = get_the_excerpt(); //文章编辑中的摘要
            else 
                echo mb_strimwidth(strip_tags(apply_filters(‘the_content‘, $post->post_content)), 0, 170,"……"); 
//文章编辑中若无摘要,自动截取文章内容字数做为摘要,0表示开始的位置,170表示结束的位置
             ?>
        </p>
    </li>
<?php  endwhile; endif; wp_reset_query(); ?>
</ul>

  这个方法是不是还不错,感兴趣的朋友可以去试试。

以上是关于内容字数做为摘要的主要内容,如果未能解决你的问题,请参考以下文章