Forums

Popularity Contest without pages? (3 posts)

  1. thehealthyskeptic
    Member
    Posted 4 weeks 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 3 weeks 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 1 week 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!

Reply

You must log in to post.

About this Topic