WordPress.org

Ready to get started?Download WordPress

Forums

Flexible Posts Widget
[resolved] Exclude posts by ID (3 posts)

  1. czcsabi
    Member
    Posted 1 year ago #

    Hi,

    A nice addition would be if one could specify to exclude some posts/pages by ID. This would improve the functionality of the plugin even more making it a one-stop-shop for post widgets.
    The Random Post for Widget plugin already has it:

    function form($instance)
      {
        $instance = wp_parse_args( (array) $instance, array( 'title' => '' ) );
        $title = $instance['title'];
    	$noofpost = $instance['noofpost'];
    	$hidepost = $instance['hidepost'];
    ?>
      <p>
      <label for="<?php echo $this->get_field_id('title'); ?>">Title: <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo attribute_escape($title); ?>" /></label>
      <label for="<?php echo $this->get_field_id('noofpost'); ?>">No. of Post: <input class="widefat" id="<?php echo $this->get_field_id('noofpost'); ?>" name="<?php echo $this->get_field_name('noofpost'); ?>" type="text" value="<?php echo attribute_escape($noofpost); ?>" /></label>
      <label for="<?php echo $this->get_field_id('hidepost'); ?>">Exclude Posts by ID(comma seperated): <input class="widefat" id="<?php echo $this->get_field_id('hidepost'); ?>" name="<?php echo $this->get_field_name('hidepost'); ?>" type="text" value="<?php echo attribute_escape($hidepost); ?>" /></label>
      </p>
    <?php
      }
    
      function update($new_instance, $old_instance)
      {
        $instance = $old_instance;
        $instance['title'] = $new_instance['title'];
    	$instance['noofpost'] = $new_instance['noofpost'];
    	$instance['hidepost'] = $new_instance['hidepost'];
        return $instance;
      }
    
      function widget($args, $instance)
      {
        extract($args, EXTR_SKIP);
    
        echo $before_widget;
        $title = empty($instance['title']) ? ' ' : apply_filters('widget_title', $instance['title']);
    	$noofpost = $instance['noofpost'];
    	$hidepost = $instance['hidepost'];
    
        if (!empty($title))
          echo $before_title . $title . $after_title;
    	if (!empty($noofpost))
    		{
    	  		$noofpost;
    	  	}
    	else
    		{
    	 		$noofpost=5;
    	  	}
        // WIDGET CODE GOES HERE
    	$arr = explode(",",$hidepost);
    	$args = array(
    	'post__not_in' => $arr,
    	'post_type' => 'post',
    	'posts_per_page' => $noofpost,
    	'orderby' => rand
    	);
    	query_posts( $args );
    	if (have_posts()) :
    		echo "<ul>";
    		while (have_posts()) : the_post();
    			echo "<li><a href='".get_permalink()."'>".get_the_title();
    			echo "</a></li>";	
    
    		endwhile;
    		echo "</ul>";
    	endif;
    	wp_reset_query();
    
        echo $after_widget;

    Best Regards,
    Csaba

    http://wordpress.org/extend/plugins/flexible-posts-widget/

  2. DaveE
    Member
    Plugin Author

    Posted 1 year ago #

    Hi Csaba,

    Thanks for the suggestion. I'll add it to the feature request queue. For now, you could accomplish the same thing by using a special category, tag or other taxonomy & term and only map the posts/pages you want to that term. Then, get posts from that term with FPW.

    Cheers!

  3. czcsabi
    Member
    Posted 1 year ago #

    Hi Dave,

    thank you for your reply and suggestion for a workaround.

    Best Regards.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.