打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
WordPress调用最新、热门、随机文章

Exo me?看到标题是不是被吓了一跳呢?由于最近重装了系统,有一些保存在C盘的文档忘记备份了,其中就有关于WordPress调用最新、热门、随机文章的示例,因此还是记录在博客上比较重要,不仅可以随时随地拿出来看看,还能顺路唠嗑几句。


最近包揽了两个外包项目,还在努力中,博客似乎真的有一段时间没更新了呢,不说了献上干货(笔记)吧。

调用最新文章:

<?PHP query_posts(‘showposts=14′); ?><ul><?php while (have_posts()) : the_post(); ?><li><a title=”<?php the_title(); ?>” href=”<?php the_permalink() ?>”><?php the_title(); ?></a></li><?php endwhile; ?></ul>

调用热门文章:

<ul><?php$post_num = 14; // 设置调用条数$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><?phpglobal $post;$postid = $post->ID;$args = array( ‘orderby’ => ‘rand’, ‘post__not_in’ => array($post->ID), ‘showposts’ => 14);$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(); ?>” title=”<?php the_title_attribute(); ?>”><?php the_title(); ?></a></li><?php endwhile; ?></ul>
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
WordPress无插件调用最新、热门、随机文章实例代码【wordpress随机文章】
wordpress最新文章列表怎么设置成不同样式
WordPress主题制作导航的N种方法
为你的wordpress创建面包屑导航(代码方式)|零点网
夢開始的地方 ? Blog Archive ? wordpress模板各文件函数解析
WordPress 主题简明教程
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服