Also, I’d like to set it up so that the popularity rankings don’t appear on pages. Can anyone help?
In response to your first question, you can show only posts by editing the popularity-contest.php file. Around the line 1377 there’s the following MySQL query:
$posts = $wpdb->get_results("
SELECT ID, post_title
FROM $wpdb->posts
LEFT JOIN $wpdb->ak_popularity pop
ON $wpdb->posts.ID = pop.post_id
$join
WHERE post_status = 'publish'
AND post_date < NOW()
$where
$groupby
ORDER BY pop.total DESC
LIMIT ".intval($limit)
);
That needs to be replaced by the following:
$posts = $wpdb->get_results("
SELECT ID, post_title
FROM $wpdb->posts
LEFT JOIN $wpdb->ak_popularity pop
ON $wpdb->posts.ID = pop.post_id
$join
WHERE post_status = 'publish'
AND post_date < NOW()
AND post_type = 'post'
$where
$groupby
ORDER BY pop.total DESC
LIMIT ".intval($limit)
);
The key here being the “AND post_type = ‘post'” bit which tells the plugin to look just for posts and not pages.
That’ll make the akpc_most_popular(); function show only posts, and not pages.
As for your second question… again, you’ll have to edit the plugin file around the line 1651. Changing this:
if (is_feed() || is_admin_page() || get_post_meta($post->ID, 'hide_popularity', true) || !$show) {
for this:
if (is_feed() || is_admin_page() || get_post_meta($post->ID, 'hide_popularity', true) || !$show || is_page()) {
The key being “|| is_page()” which prevents the popularity to appear on pages. They will still appear on posts though.
Hope that helps!
The comments tab still seems to show the comments on pages, how do i remove this as well from the popularity contest? Comment tab. By the way thank you wp_guy for the code, it really helped me getting the pages off the popularity contest. 🙂
how to show the_excerpt and custom fields?
now popularity contest displays only the_title …
thanks for support 🙂
Thanks Wp_guy. I have been struggling for days to find the answer to the first question.