web建站教程
     
  1. 首页
  2. 前端UI组件库
  3. AI项目和框架
  4. 前端知识
  5. AI应用
  6. IT知识
  7. ComfyUI插件
  8. 地图大全
  9. 休息站

wordpress如何获取网站的最新文章、热门文章、随机文章?

1272 ℃

wordpress如何利用代码获取网站的最新文章热门文章随机文章?下面web建站小编给大家详细介绍一下具体代码!

获取最新文章​

<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>

wordpress当前分类下随机文章调用代码

wordpress建站利用orderby调用全站随机文章

wordpress调用全站热门文章(代码介绍)

wordpress调用指全站最新文章(代码介绍)

标签: 最新文章 热门文章 获取文章 随机文章

上面是“wordpress如何获取网站的最新文章、热门文章、随机文章?”的全面内容,想了解更多关于 wordpress 内容,请继续关注web建站教程。

当前网址:https://ipkd.cn/webs_3344.html

声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

当前位置: 首页 > wordpress
扣子空间 – 免费全能AI办公智能体
Trae:新一代免费的AI编程工具
日历:
上一篇:
下一篇:
x 打工人ai神器
x 扫一扫打开藏历小程序

打开微信“扫一扫”查看今日藏历!