以下是调用指定分类文章列表的一个方法,作者如果有填写文章摘要则直接调用摘要;如果文章摘要忘记写了则自动截取文章内容字数做为摘要。这个方法也适用于调用description标签
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
<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> |
这个方法是不是还不错,感兴趣的朋友可以去试试。