自定义页面中获取wordpress的文章

2025-12-23 07:53:52

1、引用wp-blog-header.php文件,如wordpress放到blog目录中,需要加入目录信息,如下

require('blog/wp-blog-header.php');

2、使用get_posts获取数据

//定义一个数组,存储设置信息

$args = array( 'numberposts' => 10, 'post_status'=>"publish",'post_type'=>"post",'orderby'=>"post_date");

依次为,数量=10,发布的文章,提取post类型(wordpress有很多类型),按日期排序。

//使用get_posts获取数据

 $postslist = get_posts($args);

3、获取数据库,显示数据

<ul>

<li><a href='<?php the_permalink(); ?>' title='<?php the_title() ?>' target='_blank'><strong><?php the_title() ?></strong></a><?php the_excerpt(); ?></li>

</ul>

the_permalink() 文章的永久链接

the_title()  文章标题

the_excerpt()  文章内容的简述

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢