WordPress无插件调用最新、热门、随机文章实例代码
2021-05-02 21:15:52 调用最新文章: <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> 声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。 如涉及版权问题,请提交至online#300.cn邮箱联系删除。