WordPress.org

Ready to get started?Download WordPress

Forums

Recent Posts with Excerpts
[resolved] Exclude categories and tags (1 post)

  1. JGeo
    Member
    Posted 2 years ago #

    I wanted to use this plugin with the option to exclude certain categories and tags. I modified the code. Maybe this could be added to a future version, so I won't need forked code on my site. And to help others of course.

    I commented-out those lines:

    // retrieve last n blog posts
    $q = 'showposts='.$instance['numposts'];

    until just before
    query_posts($q);
    and replaced it by

    query_posts('tag='.$instance['extag']);
    $extag = get_query_var('tag_id');
    query_posts('tag='.$instance['tag']);
    $intag = get_query_var('tag_id');
    $q = array(
       'showposts'=>$instance['numposts'],
       'cat'=>$instance['cat'],
       'category__not_in'=>$instance['excat'],
       'tag__in'=>$intag,
       'tag__not_in'=>$extag,
    );

    Furthermore, I added after the lines

    $instance['cat'] = $new_instance['cat'];
    $instance['tag'] = $new_instance['tag'];

    those new lines:

    $instance['excat'] = $new_instance['excat'];
    $instance['extag'] = $new_instance['extag'];

    And after the line
    <?php wp_dropdown_categories...
    I added the lines

    <p><label for="<?php echo $this->get_field_id('excat'); ?>"><?php _e('Exclude category: '); ?><br />
    <?php wp_dropdown_categories(array('name' => $this->get_field_name('excat'), 'show_option_all' => __('Exclude none'), 'hide_empty'=>0, 'hierarchical'=>1, 'selected'=>$instance['excat'])); ?></label></p>

    and after

    <br /><small><?php _e('Enter post tags separated by commas (\'cat,dog\')'); ?></small>
    </p>

    I added

    <p>
    <label for="<?php echo $this->get_field_id('extag'); ?>"><?php _e('Exclude tags:'); ?></label>
    <input class="widefat" id="<?php echo $this->get_field_id('extag'); ?>" name="<?php echo $this->get_field_name('extag'); ?>" type="text" value="<?php echo $instance['extag']; ?>" />
    </p>

    That was all.

    http://wordpress.org/extend/plugins/recent-posts-with-excerpts/

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic