打开APP
userphoto
未登录

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

开通VIP
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> 

如对本文有所疑问,请点击进入脚本之家知识社区提问。







http://www.jb51.net/cms/85822.html
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
WordPress调用最新、热门、随机文章
wordpress最新文章列表怎么设置成不同样式
wordpress调用随机文章代码 | WordPress啦!
WordPress如何使文章列表样式多样化
站外以HTML的形式调用wordpress文章
为WordPress添加【随机文章】功能
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服