WordPress.org

Ready to get started?Download WordPress

Forums

WP Most Popular
Exclude one or more category from results (3 posts)

  1. andrereitz
    Member
    Posted 8 months ago #

    Is there a way to exclude categories from results? I was able to do it in other plugins/widgets but can`t find a way to do in this plugin

    http://wordpress.org/plugins/wp-most-popular/

  2. sannevanschie
    Member
    Posted 7 months ago #

    I found a way to exclude categories, it's kind of a work around but it works. First I run a counter. Then I set the limit a lot higher than the limit i want (40), then i put in a continue statement if it's the caregory i want to exclude. If the counter is at the limit i really want(10), i put in the break statement. It works perfectly.

    Here's my code:

    <!--most populair posts-->
    <?php $count = 1; //setting the counter
    
    $posts = wmp_get_popular( array( 'limit' => 40, 'post_type' => 'post', 'range' => 'monthly' ) ); //setting a higher limit
    global $post;
    if ( count( $posts ) > 0 ): foreach ( $posts as $post ):
    setup_postdata( $post );
    
    if ( in_category( 'exclude_this_category' )) { continue; } ?><!--exclude the unwanted category-->
    
    <a href="<?php the_permalink() ?>" title="<?php echo esc_attr(get_the_title() ? get_the_title() : get_the_ID()); ?>"><?php if ( get_the_title() ) the_title(); else the_ID(); ?></a>
    
    <?php $count++; //add 1 to the counter
    if ($count == 11) {break;} //break when i have run the loop 10 times
    endforeach; endif;?>
    <!--most populair posts-->

    Hope this helps

  3. andrereitz
    Member
    Posted 7 months ago #

    Great, thanks for sharing!

    I was doing this but manually, I was increasing the posts in widget in case some of not showing category take espace ¬¬!

    I'll definitely try this!
    Thank you!

Reply

You must log in to post.

About this Plugin

About this Topic