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制止复制内容的完成办法

1、右键复制时显示提醒语 把上面代码放到footer.php里即可 复制代码代码如下:<html> <head><title>防...

wordpress抓取文章第一张近程图片保留到本地的办法

这个举措咱们应用一个hook来完成: 复制代码代码如下:add_action('publish_post', 'fetch_images',999); 再...

较完满的WordPress文章摘要(截断)计划分享

当然, 尚有诸位长辈也曾把以上三种计划结合一二, 以达到更宽泛的顺应度. 不过, 这厢先前在网路上搜寻许久, ...

WordPress中用于获取文章作者与分类信息的办法整顿

作者 查问和某些作者(用户)无关的文章,能够应用 4 个参数: author(整数):用户 ID author_name(...

修正PHP脚本使WordPress阻拦渣滓评论的办法示例

阻拦英文渣滓评论 因为绝大少数的渣滓评论都是英文的,所以国际不少冤家在应用 Some Chinese Please 插件,...

wordpress设置友谊链接只在首页显示的办法

关于有的主题,当从后盾小工具中增加友谊链接后,却发现其是为全站显示的。假如只心愿让它在首页显示,则能...

需求提交

客服服务