做網站過程中,如果想對自己網站中的文章進行排序,就可以利用熱門文章程式碼來自動呼叫,熱門文章可以分為二種方法:按照文章瀏覽量和文章評論數。下面是二種方式來呼叫某一個分類下熱門文章的程式碼。

WordPress 程式呼叫按照瀏覽量來呼叫某一個分類下的熱門文章程式碼:

<?php if (have_posts()) : ?>
<?php query_posts('cat=5' . $mcatID. '&caller_get_posts=1&showposts=16&v_sortby=views'); ?>
<?php while (have_posts()) : the_post(); ?>
<li><a href="<?php the_permalink() ?>" title="<?php the_title() ?>"><?php the_title() ?></a></li>
<?php endwhile;?>
<?php endif; wp_reset_query(); ?>

WordPress 程式呼叫按照評論量來呼叫某一個分類下的熱門文章 (熱評文章) 程式碼:

<?php
$post_num = 10; // 設定呼叫條數
$args = array(
'post_password' => '',
'post_status' => 'publish', // 只選公開的文章.
'cat' => 101,//分類文章
'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(); ?>
<li><?php comments_number('0', '1', '%' );?> 次評論: <br><a href="http://<?php%20the_permalink()%20?>" title="<?php the_title() ?>"><?php the_title() ?></a></li>
<?php } wp_reset_query();?>