本页目录
在主题开发中,会有一些显示最新或是最热门的文章的小工具,这一节的开发就和大家分享下,如何调用这些数据。
- 代码来源:详情
最新:
其中的数字 6 为日志显示篇数。
<?php query_posts('showposts=6&cat=1'); ?><?php while (have_posts()) : the_post(); ?><a href="<?php the_permalink() ?>" rel="external nofollow" rel="external nofollow" ><?php the_title(); ?></a><?php endwhile;?>热门:
挑选评论比较多的日志,并依次从高至底排列。
<?php$post_num = 10; // 显示篇数$args = array('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(); ?><a href="<?php the_permalink(); ?>" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" ><?php the_title(); ?></a> <?php } wp_reset_query();?>