16 Sep 2010调用WP热评文章
答小小童鞋的问题,在调用WP热评文章的时候如果没有相关文章,则显示“当前无热评文章”。
以前的代码是直接调用其SQL语句,今天新分享一段PHP代码,更为简洁,效率更高。只需要在合适的地方插入如下代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 | <?php $result = $wpdb->get_results("SELECT comment_count,ID,post_title FROM $wpdb->posts ORDER BY comment_count DESC LIMIT 0 , 10"); foreach ($result as $post) { setup_postdata($post); $postid = $post->ID; $title = $post->post_title; $commentcount = $post->comment_count; if ($commentcount = ) { ?> <li>当前无热评文章</li> <?php } } ?> if ($commentcount != 0) { ?> <li><a href="<?php echo get_permalink($postid); ?>" title="<?php echo $title ?>"> <?php echo $title ?></a> (<?php echo $commentcount ?>)</li> <?php } } ?> |
Til next time,
Jason at 00:00