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