找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 1979|回复: 0

[分享] wordpress教程:无插件调用最新、热门、随机文章实例代

[复制链接]
发表于 2016-1-28 14:25:22 | 显示全部楼层 |阅读模式 来自 河南省新乡市

调用最新文章:

复制代码代码如下:
  1. <ul>
  2. <?php $post_query = new WP_Query(‘showposts=10′);
  3. while ($post_query->have_posts()) : $post_query->the_post();
  4. $do_not_duplicate = $post->ID; ?>
  5. <li><a href=”<?php the_permalink(); ?>”><?php the_title(); ?></a></li>
  6. <?php endwhile;?>
  7. </ul>
复制代码
调用热门文章:

复制代码代码如下:
  1. <ul>
  2. <?php
  3. $post_num = 10; // 设置调用条数
  4. $args = array(
  5. ‘post_password’ => ”,
  6. ‘post_status’ => ‘publish’, // 只选公开的文章.
  7. ‘post__not_in’ => array($post->ID),//排除当前文章
  8. ‘caller_get_posts’ => 1, // 排除置顶文章.
  9. ‘orderby’ => ‘comment_count’, // 依评论数排序.
  10. ‘posts_per_page’ => $post_num
  11. );
  12. $query_posts = new WP_Query();
  13. $query_posts->query($args);
  14. while( $query_posts->have_posts() ) { $query_posts->the_post(); ?>
  15. <li><a href=”<?php the_permalink(); ?>” title=”<?php the_title(); ?>”><?php the_title(); ?></a></li>
  16. <?php } wp_reset_query();?>
  17. </ul>
复制代码
调用随机文章:

复制代码代码如下:
  1. <ul>
  2. <?php
  3. global $post;
  4. $postid = $post->ID;
  5. $args = array( ‘orderby’ => ‘rand’, ‘post__not_in’ => array($post->ID), ‘showposts’ => 10);
  6. $query_posts = new WP_Query();
  7. $query_posts->query($args);
  8. ?>
  9. <?php while ($query_posts->have_posts()) : $query_posts->the_post(); ?>
  10. <li><a href=”<?php the_permalink(); ?>” rel=”bookmark” title=”<?php the_title_attribute(); ?>”><?php the_title(); ?></a></li>
  11. <?php endwhile; ?>
  12. </ul>
复制代码
查看更多 wordpress教程 wordpress主题

发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;

如何回报帮助你解决问题的坛友,好办法就是点击帖子下方的评分按钮给对方加【金币】不会扣除自己的积分,做一个热心并受欢迎的人!

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则 需要先绑定手机号

关闭

站长推荐上一条 /1 下一条

QQ|侵权投诉|广告报价|手机版|小黑屋|西部数码代理|飘仙建站论坛 ( 豫ICP备2022021143号-1 )

GMT+8, 2024-5-2 02:53 , Processed in 0.037821 second(s), 8 queries , Redis On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表