Bài viết ngẫu nhiên , bài viết xem nhiều nhất

bài viết ngẫu nhiên trong wordpress , bài viết xem nhiều nhất

Các bạn có thể không dùng blugin khi làm cái này cũng được sau đây mình xin giới thiệu 2 code trên như sau . Thấy hay nhớ like cho mình nhé 
<h3>Bài ngẫu nhiên</h3>
    <div class="box">
      <?php
 $rand_posts = get_posts('numberposts=so_bai_hien_thi&orderby=rand');
 foreach( $rand_posts as $post ) :
 ?>
      <li > <a style="font-weight: bold;" href="<?php the_permalink(); ?>">
        <?php the_title(); ?>
        </a></li>
      <?php endforeach; ?>
      </li>
</div>


Còn đây là code hiển thị bài viết được xem nhiều nhất :




<h3>Xem nhiều nhất</h3>
<div class="box">
        <?php $popular_number = so_bai_hien_thi; $result = $wpdb->get_results("SELECT comment_count,ID,post_title,post_content FROM $wpdb->posts ORDER BY comment_count DESC LIMIT 0 , $popular_number");
            foreach ($result as $post) {
            setup_postdata($post);
            $postid = $post->ID;
            $title = $post->post_title;
            $content = $post->post_content;
            $commentcount = $post->comment_count;
            if ($commentcount != 0) { ?>
            <li>
            <a style="font-weight: bold;" href="<?php echo get_permalink($postid); ?>" title="<?php echo $title ?>"><?php echo $title ?></a></li>
            <?php } } ?>
</div>

SHARE

trungthan

  • Image
  • Image
  • Image
  • Image
  • Image

0 nhận xét:

Đăng nhận xét