WordPress.org

Support

Support » Plugins and Hacks » Popularity Contest without pages?

Popularity Contest without pages?

  • I just installed the Popularity Contest plugin, and I’ve configured it so that the most popular posts show up in the sidebar. However, it includes pages as well as posts which I do not want. Is there some way to eliminate the pages from the popularity rankings?

Viewing 5 replies - 1 through 5 (of 5 total)
  • 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.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Popularity Contest without pages?’ is closed to new replies.