WordPress.org

Ready to get started?Download WordPress

Forums

Popularity Contest without pages? (6 posts)

  1. thehealthyskeptic
    Member
    Posted 6 years ago #

    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?

  2. thehealthyskeptic
    Member
    Posted 6 years ago #

    Also, I'd like to set it up so that the popularity rankings don't appear on pages. Can anyone help?

  3. wp_guy
    Member
    Posted 5 years ago #

    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!

  4. avin89
    Member
    Posted 5 years ago #

    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. :)

  5. YouON
    Member
    Posted 5 years ago #

    how to show the_excerpt and custom fields?
    now popularity contest displays only the_title ...

    thanks for support :)

  6. jeeremie
    Member
    Posted 5 years ago #

    Thanks Wp_guy. I have been struggling for days to find the answer to the first question.

Topic Closed

This topic has been closed to new replies.

About this Topic