wordpress 获取指定数量的文章信息

define('WP_USE_THEMES', false); //无需使用主题
include_once('./wp-load.php');  //根据wordpress路径来调用 需要同服务器下
function get_posts_DESC($number){//获取$number条最新文章
$args = array(
    'numberposts'=>$number,
    'offset'=>0,
    'category'=>"",
    'orderby'=>'post_date',
    'order'=>'DESC',
    'include'=>"",
    'exclude'=>"",
    'meta_key'=>"",
    'meta_value'=>"",
    'post_type'=>'post',
    'post_mime_type'=>"",
    'post_parent'=>"",
    'post_status'=>'publish'
);
$posts_array = get_posts($args);
$postnum=count($posts_array);
return $posts_array;
}
function get_posts_ASC($number){//获取$number条最老文章
$args = array(
    'numberposts'=>$number,
    'offset'=>0,
    'category'=>"",
    'orderby'=>'post_date',
    'order'=>'ASC',
    'include'=>"",
    'exclude'=>"",
    'meta_key'=>"",
    'meta_value'=>"",
    'post_type'=>'post',
    'post_mime_type'=>"",
    'post_parent'=>"",
    'post_status'=>'publish'
);
$posts_array = get_posts($args);
$postnum=count($posts_array);
//$posts_array[$x]->post_title;//文章标题
return $posts_array;
}
© 版权声明
THE END
喜欢就支持一下吧
点赞7 分享