Created
February 10, 2017 21:00
-
-
Save mwordpress/dd70ed90c4a92d2945a18b9e49ea2386 to your computer and use it in GitHub Desktop.
the codes listed here is part of the following article : https://www.mwordpress.net/how-to-display-your-most-popular-posts-with-thumbnails-in-wordpress/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$postscount = 5; | |
$param = array ( | |
'post__in' => get_post_commented($post_id = NULL), | |
'orderby' => 'comment_count', | |
'posts_per_page' => $postscount | |
); | |
$most_popular = new WP_Query($param); | |
echo '<ul>'; | |
while ($most_popular->have_posts()) : $most_popular->the_post(); | |
?> | |
<li> | |
<h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3> | |
<?php if ( has_post_thumbnail() ) : ?> | |
<div class="thumbnail"> | |
<?php the_post_thumbnail('thumbnail'); ?> | |
</div> | |
<?php endif; ?> | |
</li> | |
<?php | |
endwhile; | |
wp_reset_query(); | |
echo '</ul>'; | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$postscount = 5; | |
$param = array ( | |
'post__in' => get_post_commented($post_id = NULL), | |
'orderby' => 'comment_count', | |
'posts_per_page' => $postscount | |
); | |
$most_popular = new WP_Query($param); | |
echo '<ul>'; | |
while ($most_popular->have_posts()) : $most_popular->the_post(); | |
?> | |
<li> | |
<h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3> | |
<div class="thumbnail"> | |
<?php show_thumb(80, 50, 'img-responsive', $post->ID, 100); ?> | |
</div> | |
</li> | |
<?php | |
endwhile; | |
wp_reset_query(); | |
echo '</ul>'; | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* Get Most Posts Commented ID | |
* @Mouad Achemli | |
*/ | |
function get_post_commented($post_id = NULL) { | |
global $wpdb; | |
$date_lookup = ''; | |
$table = $wpdb->prefix . "comments"; | |
if ( NULL === $post_id ) | |
$post_id = get_the_ID(); | |
// Get list of commented posts in the current mounth | |
$sql = "SELECT comment_approved, comment_post_ID, comment_author, comment_author_email, comment_date, comment_content, comment_approved, comment_type, comment_parent | |
FROM " . $table . " WHERE comment_date > '%$date_lookup%' AND comment_date >= '".date('Y-m-d', strtotime(date('Y-m-01 00:00:00′)))."' ORDER BY comment_date DESC"; | |
$post_ids = $wpdb->get_results($sql); | |
$output = array(); | |
foreach ($post_ids as $id) { | |
array_push($output,$id->comment_post_ID); | |
} | |
$result = array_unique($output); | |
return $result; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment