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>

以上就是安达网络工作室关于《WordPress无插件调用**、热门、随机文章实例代码》的一些看法。更多内容请查看本栏目更多内容!

版权声明:本文为 安达网络工作室 转载文章,如有侵权请联系我们及时删除。
相关文章
WordPress中使主题支持小工具以及增加插件启用函数

让主题支持小工具 WordPress 的小工具(widget)是一大特征,它让用户自在拖动组合内容,而且任何插件和主题...

详解WordPress中分类函数wp_list_categories的应用

wp_list_categories 函数是 WordPress 中用来列举零碎中分类的函数,该函数领有许多管制输入的参数,明天忽...

WordPress中限度非治理员用户在文章后只能评论一次

之前有网友提出,在WordPress中有没有方法完成每篇文章只容许用户评论一次? 暂不说这个需要有没有用,毕竟...

WordPress评论IP地址显示为127.0.0.1的处理方法

穆童博客应用的是Wordpress顺序,上次在改换了效劳器之后不知为何一切新评论的IP地址都显示为127.0.0.1。刚...

WordPress必备数据库SQL查问语句整顿

最近明月给博客和主站都部署了SSL证书,彻彻底底的退出了HTTPS站点行列。这个时期也用到了SQL查问语句来批量...

在Ubuntu 14.04上部署 PHP 环境及 WordPress

软件及版本抉择 Ubuntu 14.04 Ubuntu 是目前用户数量首屈一指的发行版,面前有大土豪保护,能够说是轻量级用...

需求提交

客服服务