WordPress显示最新文章

调用最新文章

1
2
3
4
<?php $rand_posts = get_posts('numberposts=10&orderby=date');foreach($rand_posts as $post) : ?>
<li><a href="<?php the_permalink(); ?>"> <?php echo mb_strimwidth(get_the_title(), 0, 32, ''); ?></a></li>
<?php endforeach;?>
numberposts=10最新10篇文章、orderby=date按日期调用

调用最新五篇文章

1
2
3
4
5
6
7
<?php query_posts('showposts=5'); ?>
<ul>
<?php while (have_posts()) : the_post(); ?>
<li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li>
<?php endwhile;?>
</ul>
其中的showposts=5为最新文章数量,可自定义数值。

调用分类ID为1的分类下的五篇最新文章

1
2
3
4
5
<?php $rand_posts = get_posts('numberposts=5&category=1&orderby=date');foreach($rand_posts as $post) : ?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endforeach;?>
numberposts=5 五为文章数值的限定
category=1 1为分类ID的限定