Created
July 10, 2018 08:18
-
-
Save mediter/7a762ab84505aabbe9e059f784a9efcf to your computer and use it in GitHub Desktop.
[WordPress Post Excerpt and Truncation] #WordPress #Excerpt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> //标题 | |
<span> | |
<?php if (has_excerpt()) { | |
echo $description = get_the_excerpt(); //文章编辑中的摘要 | |
}else { | |
echo mb_strimwidth(strip_tags(apply_filters('the_content', $post->post_content)), 0, 170,"……"); | |
//文章编辑中若无摘要,自定截取文章内容字数做为摘要 | |
} ?> | |
</span> | |
</li> | |
<?php endwhile; endif; wp_reset_query(); ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment