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 内容,请继续关注web建站教程。
当前网址:https://ipkd.cn/webs_3344.html
workflows工作流
一位美丽的女士在座机上讲话ComfyUI工作流
令人着迷的一只老虎ComfyUI工作流
森林里有一个皮肤像抛光黑曜石的生物
斗鸡场威武雄鸡ComfyUI工作流
一个可爱的口袋妖怪ComfyUI工作流
一只可爱的小鸟在飞翔ComfyUI工作流
一个超现实和超现实的场景,在森林中心有一座蛇形的房子
一位穿着优雅银色装饰黑色连衣裙的苗条模特
猜你喜欢
声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

2023年程序猿如何给自己开启一场烟花盛会
利用css3做一个动态loading效果
利用css绘画棋盘布局(象棋)
利用canvas画几个好玩的星云物种
css3画弹珠,可以滚动!
css3绘制一个会动的大嘴鸟
利用html5+css3实现滚雪球效果(附代码)










