會有一些顯示最新或是最熱門的文章的小工具,這一節的開發就和大家分享下,如何調用這些數據
在主題開發中,會有一些顯示最新或是最熱門的文章的小工具,這一節的開發就和大家分享下,如何調用這些數據。
- 代碼來源:詳情
最新:
其中的數字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();?>