wordpress免插件调用最新文章的四种方法

方法一、wp_get_archvies函数

wordpress最新文章的调用可以使用一行很简单的模板标签wp_get_archvies来实现

get_archives(‘postbypost’,10);  (显示10篇最新更新文章)

或者

wp_get_archives(‘type=postbypost&limit=20&format=custom’);

type=postbypost:按最新文章排列

limit:限制文章数量最新20篇

format=custom:用来自定义这份文章列表的显示样式(fromat=custom也可以不要,默认以UL列表显示文章标题。)

方法二、query_posts()函数

通过WP的query_posts()函数也能调用最新文章列表的好处就是可以通过Loop控制显示。

query_posts('showposts=6&cat=-10');
 
while (have_posts()) : the_post();
 
the_permalink();
the_title();
 
endwhile;

上面代码的意思是 读取6篇文章,排除分类ID为10里面的文章

三、使用WP_Query函数

$post_query = new WP_Query('showposts=10');
 
while ($post_query->have_posts()) : $post_query->the_post();
 
$do_not_duplicate = $post->ID;
 
the_permalink(); the_title();
 
endwhile;

四、使用 get_results 函数

$result = $wpdb->get_results(“SELECT ID,post_title FROM $wpdb->posts where post_status=’publish’ and post_type=’post’ ORDER BY ID DESC LIMIT 0,10″);
 
foreach ($result as $post) {
 
setup_postdata($post);
 
$postid = $post->ID;
 
$title = $post->post_title;

欢迎关注我的公众号“xx主题网”,原创技术文章第一时间推送。

文章来源:https://www.xxzhuti.com/810.html


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值