WordPress无插件调用最新、热门、随机文章实例代码

WordPress无插件调用最新、热门、随机文章实例代码,第1张

WordPress="superseo">ss无插件调用最新、热门、随机文章实例代码

WordPress没有调用最新、热门、随机文章的插件。具体实现代码如下。感兴趣的朋友可以参考一下。希望对你打电话报新闻有帮助。

调用最新文章:

复制代码代码如下:
<ul>
<?php$post_query=newWP_Query(‘showposts=10′);
while($post_query->have_posts()):$post_query->the_post();
$do_not_duplicate=$post->ID;?>
<li><ahref=”<?phpthe_permalink();?>”><?phpthe_title();?></a></li>
<?phpendwhile;?>
</ul>

调用热门文章:

复制代码代码如下:
<ul>
<?php
$post_num=10;//设置调用条数
$args=array(
‘post_password’=>”,
‘post_status’=>‘publish’,//只选公开的文章.
‘post__not_in’=>array($post->ID),//排除当前文章
‘caller_get_posts’=>1,//排除置顶文章.
‘orderby’=>‘comment_count’,//依评论数排序.
‘posts_per_page’=>$post_num
);
$query_posts=newWP_Query();
$query_posts->query($args);
while($query_posts->have_posts()){$query_posts->the_post();?>
<li><ahref=”<?phpthe_permalink();?>”title=”<?phpthe_title();?>”><?phpthe_title();?></a></li>
<?php}wp_reset_query();?>
</ul>

调用随机文章:

复制代码代码如下:
<ul>
<?php
global$post;
$postid=$post->ID;
$args=array(‘orderby’=>‘rand’,‘post__not_in’=>array($post->ID),‘showposts’=>10);
$query_posts=newWP_Query();
$query_posts->query($args);
?>
<?phpwhile($query_posts->have_posts()):$query_posts->the_post();?>
<li><ahref=”<?phpthe_permalink();?>”rel=”bookmark”title=”<?phpthe_title_attribute();?>”><?phpthe_title();?></a></li>
<?phpendwhile;?>
</ul>

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zz/772535.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-03
下一篇 2022-05-03

发表评论

登录后才能评论

评论列表(0条)

保存