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;