แสดง 10 โพสต์ยอดนิยมในช่วง 30 วันที่ผ่านมา โดยไม่ใช้ปลั๊กอิน
สำหรับการแสดง 10 โพสต์ยอดนิยมในช่วง 30 วันที่ผ่านมา โดยไม่ใช้ปลั๊กอิน จะเป็นการดึงเอาข้อมูลโพสต์ล่าสุดบนฐานข้อมูล wordpress ในช่วงระยะเวลา 30 วันที่ผ่านมา มาแสดงบนเว็บเพจยังตำแหน่งที่ต้องการ เช่น single.php, page.php หรือ index.php
<ul> <?php function filter_where($where = '') { //โพสต์ในช่วง 30 วันที่ผ่านมา $where .= " AND post_date > '" . date('Y-m-d', strtotime('-30 days')) . "'"; return $where; } add_filter('posts_where', 'filter_where'); query_posts('post_type=post&posts_per_page=10&orderby=comment_count&order=DESC'); while (have_posts()): the_post(); ?> <li><a href="<?php the_permalink(); ?>" title="<?php printf(esc_attr('Permalink to %s'), the_title_attribute('echo=0')); ?>" rel="bookmark"><?php the_title(); ?></a></li> <?php endwhile; wp_reset_query(); ?> </ul>
note.
-30 days จะเป็นการดึงโพสต์ใน 30 วันล่าสุดมาแสดง
posts_per_page=10 จะเป็นการดึงเอาโพสต์ 10 อันดับแรกมาแสดง