會(huì)有一些顯示最新或是最熱門的文章的小工具,這一節(jié)的開發(fā)就和大家分享下,如何調(diào)用這些數(shù)據(jù)
在主題開發(fā)中,會(huì)有一些顯示最新或是最熱門的文章的小工具,這一節(jié)的開發(fā)就和大家分享下,如何調(diào)用這些數(shù)據(jù)。
- 代碼來源:詳情
最新:
其中的數(shù)字6為日志顯示篇數(shù)。
<?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; // 顯示篇數(shù)
$args = array(
'post_status' => 'publish', // 只選公開的文章.
'post__not_in' => array($post->ID),//排除當(dāng)前文章
'caller_get_posts' => 1, // 排除置頂文章.
'orderby' => 'comment_count', // 依評論數(shù)排序.
'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();?>

