WordPress based on the number of comments to get hot article examples

Source: Internet
Author: User
Tags comments php file

A lot of people use WordPress often need to call WordPress popular article features, access to WordPress popular article way There are many, can be viewed by the number of articles or WordPress comments, this article mainly introduced by the number of comments to get WordPress hot articles.

Here's how to get the WordPress hot articles from the comments on the article, the code reads as follows:

<ul id= "Popular-posts" >
<?php $result = $wpdb->get_results ("Select Comment_count,id,post_title from $wpdb->posts ORDER by Comment_ Count DESC LIMIT 0, 6 ");
foreach ($result as $post) {
Setup_postdata ($post);
$postid = $post->id;
$title = $post->post_title;
$commentcount = $post->comment_count;
if ($commentcount!= 0) {?>
<li><a href= "<?php Echo get_permalink ($postid)?>" title= "<?php echo $title?>" >
<?php echo $title?></a> {<?php echo $commentcount?> comment}</li>
<?php}}?>
</ul>

Add the above section of code to the appropriate location, such as add to the single.php file, you can achieve the end of the article to display the popular article. Limit 0, 6 shows the number of articles in the code, where you can modify the number you want.

WordPress get a week top article ranking

<?php
function Mostweek ($where = ' ") {
Get articles from the last seven days
$where. = "and Post_date >". Date (' y-m-d ', Strtotime ('-7 days ')). "'";
return $where;
}
Add_filter (' Posts_where ', ' Mostweek ');?>

<?php query_posts ("v_sortby=views&caller_get_posts=1&orderby=date&v_orderby=desc&showposts= Ten ")?>
<?php if (have_posts ()): while (Have_posts ()): The_post ();?>
<li><a href= "<?php the_permalink ()?>" title= "<?php the_title ()?>" ><?php the_title ()?> </a></li>
<?php Endwhile;?>
<?php endif;?>

WordPress Access January Top articles ranking

<?php
Function mostmonth ($where = ') {
   //Get last 30 days article
    $where. = "A ND post_date > ' ". Date (' y-m-d ', Strtotime (' -30 days ')). "'";
    return $where;
}
Add_filter (' Posts_where ', ' mostmonth ');
<?php query_posts ("v_sortby=views&caller_get_ posts=1&orderby=date&v_orderby=desc&showposts=10 ")
  <?php if (have_posts ()): while ( Have_posts ()): The_post ();
      <li><a href= <?php the_permalink ()? > "title=" <?php the_title ()?> ><?php the_title () ></a></li>
  <?php Endwhile
<?php endif;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.