wordpress调用最新文章函数(可指定分类)

作者:袖梨 2022-06-25

1.调用网站所有文章只最新10条记录

 代码如下 复制代码

<?php get_archives(‘postbypost’, 10); ?>

<?php wp_get_archives(‘type=postbypost&limit=10&format=custom’); ?>

上面是调用最新10条记录哦,只不过是全站的。

2.调用指定分类最新文件

 代码如下 复制代码

<?php $posts = get_posts( "category=4&numberposts=10" ); ?>
<?php if( $posts ) : ?>

  • <?php
foreach( $posts as $post ) : setup_postdata( $post ); ?>

<?php the_title(); ?>

<?php endforeach; ?>

<?php endif; ?>

或者使用wordpress强大的API功能

 代码如下 复制代码


  • <?php query_posts('cat=15&posts_per_page=10'); while(have_posts()): the_post(); ?>

  •  
  • <?php the_title();?>

  •  <?php endwhile; wp_reset_query(); ?>

相关文章

精彩推荐