Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
[WordPress Post Excerpt and Truncation] #WordPress #Excerpt
'cat' => 1, // 分类ID
'posts_per_page' => 10, // 显示篇数
if(have_posts()) : while (have_posts()) : the_post();
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> //标题
<?php if (has_excerpt()) {
echo $description = get_the_excerpt(); //文章编辑中的摘要
}else {
echo mb_strimwidth(strip_tags(apply_filters('the_content', $post->post_content)), 0, 170,"……");
} ?>
<?php endwhile; endif; wp_reset_query(); ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.