您现在的位置是:首页 > cms教程 > WordPress教程WordPress教程

WordPress调用最新热门随机文章的方法

吴资龙2023-06-24WordPress教程已有人查阅

导读WordPress如何无插件调用 新、热门、随机文章?WordPress无插件调用 新、热门、随机文章实例代码

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

WordPress无插件调用 新、热门、随机文章,具体实现代码如下,感兴趣的朋友可以参考下哈,希望对大家在新闻调用上有所帮助

调用新文章:

<ul> 
<?php $post_query = new WP_Query(‘showposts=10′); 
while ($post_query->have_posts()) : $post_query->the_post(); 
$do_not_duplicate = $post->ID; ?> 
<li><a href=”<?php the_permalink(); ?>”><?php the_title(); ?></a></li> 
<?php endwhile;?> 
</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 = new WP_Query(); 
$query_posts->query($args); 
while( $query_posts->have_posts() ) { $query_posts->the_post(); ?> 
<li><a href=”<?php the_permalink(); ?>” title=”<?php the_title(); ?>”><?php the_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 = new WP_Query(); 
$query_posts->query($args); 
?> 
<?php while ($query_posts->have_posts()) : $query_posts->the_post(); ?> 
<li><a href=”<?php the_permalink(); ?>” rel=”bookmark” title=”<?php the_title_attribute(); ?>”><?php the_title(); ?></a></li> 
<?php endwhile; ?> 
</ul>

本文标签:

很赞哦! ()

相关源码

  • (自适应响应式)工业机床工程农业机械设备网站源码下载框架适用于工程机械、机床设备等工业领域。通过模块调整可快速转型为农业机械、物流设备展示系统。预留7种工业产品展示模板。查看源码
  • (自适应响应式)黑色LED显示屏户外广告屏网站源码下载这是一款基于PbootCMS内核开发的响应式网站模板,专门为LED显示屏及户外广告行业打造。模板适配各类显示设备,帮助企业快速搭建专业官网,展示产品与服务优势,有效提升品牌形象。查看源码
  • (自适应响应式)高端珠宝首饰奢侈品pbootcms模板下载本模板为珠宝首饰及奢侈品行业打造,采用PbootCMS内核开发,具备卓越的视觉表现力与商业转化能力。自适应设计确保在手机端呈现产品细节,后台数据实时同步,助您高效展示钻石查看源码
  • 自适应容器设备机械行业通用pbootcms网站模板本模板是一款基于PbootCMS开源内核深度开发,为容器制造、容器设备、压力容器及相关行业量身打造的高品质响应式企业网站模板。查看源码
  • (自适应)宽屏大气红色机械设备pbootcms模板源码下载为机械设备制造企业设计的响应式网站模板,采用PbootCMS内核开发。宽屏布局突出设备展示效果,红色工业风格贴合机械行业属性,支持PC端与手机端自动适配查看源码
  • (PC+WAP)楼承板建筑工程合金钢铁材料pbootcms网站源码下载为楼承板生产商及建筑工程企业设计的响应式网站模板,采用PbootCMS内核开发,同步适配电脑与移动设备浏览。通过模块化结构展示工程案例、产品参数等专业内容,帮助建筑建材企业建立标准化数字展示平台,提升行业专业形象。查看源码
分享笔记 (共有 篇笔记)
验证码: