Support » Plugins » How to Exclude Pages in Popularity Contest?

  • I’m using the latest popularity contest plugin. I want to display 10 most popular posts (pages excluded) in a normal text widget.

    I have no knowledge of PHP, but I found this code to b working but it does not exclude pages.

    <?php if (function_exists('akpc_most_popular')) { ?>
    <?php akpc_most_popular(); ?>
    <?php } ?>

    PS. I don’t mind having popularity rating on pages I just don’t want them displayed with most popular posts in my text widget.


Viewing 7 replies - 1 through 7 (of 7 total)
  • You’d probably have to modify the get_top_rated_posts function in that plugin to ignore posts with a post_type of ‘page’.

    Also to execute PHP in a Widget, consider downloading and installing Otto’s PHP Code Widget.

    Thanks for the answer but I have no idea how to do that.

    I already have a plugin that executes php in widget and I’m already using the above code in a text widget. I just need info on how to ignore posts with a post_type of ‘page’, like you said.

    Any update on this? I’m still trying to figure it out.

    Anyone know specifically how to exclude pages from Popularity Contest?

    Somewhere near line #2279, there’s a line like this:

    $str .= '<script type="text/javascript">AKPC_IDS += "'.$post->ID.',";</script>';

    You can change it into this:

    if (!is_page ()){ $str .= '<script type="text/javascript">AKPC_IDS += "'.$post->ID.',";</script>'; }

    It’s by assuming that your installation is the same with mine.

    With the above code, the “post weight JavaScript adder” will not appear on pages.

    To reset the weighs (to test):

    1. Deactivate plugin
    2. Drop wp_ak_popularity and wp_ak_popularity_options table from database.
    3. Activate plugin

    An update suggestion, post_title output is probably better to be filtered:

    apply_filters ('the_title', $post -> post_title)

    … so it’ll work with some title modifier plugins such as qTranslate.

    The above solution didn’t do the trick for me. I am not using the Contest as a widget but on a page.

    What must I change so that the pages don’t show in the pop list?


    Pretty silly really in that typically your pages are some of the most popular landing places but they are already in the top navigation. There really needs to be an easy way to turn them off. Oh well.

    You can remove posts with ‘page’ type directly from SQL query.
    Add this:

    AND post_type = ‘post’

    on line 1938. You’ll get something like this:

    function get_top_ranked_posts($limit) {
            global $wpdb;
            $temp = $wpdb;
            $join = apply_filters('posts_join', '');
            $where = apply_filters('posts_where', '');
            $groupby = apply_filters('posts_groupby', '');
            if (!empty($groupby)) {
                $groupby = ' GROUP BY '.$groupby;
            else {
                $groupby = ' GROUP BY '.$wpdb->posts.'.ID ';
            $posts = $wpdb->get_results("
                SELECT ID, post_title
                FROM $wpdb->posts
                LEFT JOIN $wpdb->ak_popularity pop
                ON $wpdb->posts.ID = pop.post_id
                WHERE post_status = 'publish'
                AND post_date < NOW()
                    AND post_type = 'post'
                ORDER BY DESC
                LIMIT ".intval($limit)

    Personally I use akpc_most_popular() function to get popular posts. And it transitively calls get_top_ranked_posts().

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘How to Exclude Pages in Popularity Contest?’ is closed to new replies.