WordPress无插件调用最新、热门、随机文章代码

  • 997 views
  • 阅读模式

调用最新文章:

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

weinxin
我的微信
这是我的微信扫一扫
年轻的老刘
  • 本文由 发表于 2015年1月9日 16:45:17
  • 转载请务必保留本文链接:https://www.uhua0318.com/diaoyongremen.html
wordpress

wordpress如何添加匿名投稿功能

因为常常浏览、学习别人的博客,我发觉一个不争的事实就是:相当一部份做得比较成功的博客都接受读者投稿(当然,可能有的是邀请写手,那也算是一种聪明的做法!),这种情况实际上是协作中的一种,反映出:一个人的...
wordpress

如何在WordPress文章中插入广告

注意,如果代码无法生效,请检查下代码中标点符号是否为英文符号 玩wordpress的朋友几乎都会在文章中插入广告,虽然不图赚钱,就是为了找个乐子。本文教你如何在文章的顶部、底部、左右两侧及任意位置添加...
wordpress

让wordpress网站飞起来?

作为wordpress网站的站长,我们可能会经常碰到一些奇怪的问题:wordpress后台打不开显示空白、wordpress后台打开非常慢。我们要问了:为什么wordpress后台打不开?为什么wor...
wordpress

wordpress如何更换后台登录界面logo

在文章开始前,我要说更换wordpress后台登录界面的logo绝对算是无聊之作,摸索这东西的人究竟要该有多闲啊!大家都知道wp-login.php是登录界面,这个界面上明显的放置着wordpress...

发表评论

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定