Exclude Post & Pagination

Question, I’m looking to customize this wordpress widget. I’m looking for it to exclude a 4 post and create pagination below. How would I go about customizing this code?

[php]<?php
class wpShowerIndexLatestEntriesWidget extends WP_Widget {
function __construct() {
parent::__construct(
‘wpshower_index_latest_entries’,
‘Homepage Latest Entries’,
array(‘description’ => __(‘Widget for displaying latest entries’, ‘outspoken’))
);
}

/**
 * Front-end display of widget.
 *
 * @see WP_Widget::widget()
 *
 * @param array $args     Widget arguments.
 * @param array $instance Saved values from database.
 */
public function widget($args, $instance) {
	extract($args);

	$limit = $instance['limit'];

	$options = array(
		'posts_per_page' => $limit + 1
	);
	$exclude = wpShower::getIndexPosts('exclude');
	if (!empty($exclude)) $options['exclude'] = implode(',', $exclude);
	$posts = get_posts($options);

	$title = apply_filters('widget_title', $instance['title']);

	echo $before_widget.$before_title.$title.$after_title;

	if (empty($posts)) {
		echo '<div class="outspoken-error">';
		if (is_admin_bar_showing()) {
			printf(__('No posts to show, please <a href="%s">add one</a>', 'outspoken'), admin_url('edit.php'));
		}
		else {
			_e('No posts to show', 'outspoken');
		}
		echo '</div>'.$after_widget;
		return;
	}

	global $post;
	$show_categories = get_theme_mod('outspoken_home_categories');
	for ($i = 0; $i < $limit; $i++):
		if (!isset($posts[$i])) break;
		$post = $posts[$i];
		setup_postdata($post);
		$image = outspoken_post_image($post->ID, 'post-thumbnail');
	?>

	<article>
		<a href="<?php the_permalink(); ?>"><img src="<?php echo esc_url($image); ?>" alt="<?php the_title_attribute(); ?>" title="<?php the_title_attribute(); ?>" /></a>
		<div>
		<?php if ($show_categories): ?>
			<div class="meta-top"><?php outspoken_entry_categories(); ?></div>
		<?php endif; ?>
			<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
		<?php
		$meta = outspoken_index_meta(false, false);
		if ($meta != ''):
		?>
			<div class="meta"><?php echo $meta; ?></div>
		<?php endif; ?>
			<div class="summary"><?php the_excerpt(); ?></div>
		</div>
	</article>

	<?php
	endfor;
	wp_reset_postdata();
	if (isset($posts[$limit])):
	?>

	<div class="load-more"><span class="loader"></span><span class="text">Load More Posts</span></div>

	<script type="text/javascript">
	jQuery(function() {
		var latest_entries_limit = <?php echo $limit; ?>;
		var latest_entries_offset = latest_entries_limit;
		jQuery('#<?php echo $args['widget_id']; ?>').on('click', '.load-more', function() {
			if (latest_entries_offset == 0) return;

			jQuery(this).addClass('active');
			jQuery.ajax({
				type: 'post',
				dataType: 'json',
				url: '<?php echo admin_url('admin-ajax.php?action=wpshower_latest_entries'); ?>',
				data: {
					limit: latest_entries_limit,
					offset: latest_entries_offset
				},
				success: function(response) {
					for (var i = 0; i < response.posts.length; i++) {
						jQuery('#<?php echo $args['widget_id']; ?> .load-more').before(
							'<article>' +
								'<a href="' + response.posts[i].permalink + '"><img src="' + response.posts[i].image + '" alt="' + response.posts[i].title + '" title="' + response.posts[i].title + '" /></a>' +
								'<div>' +
									'<div class="meta-top">' + response.posts[i].categories + '</div>' +
									'<h2><a href="' + response.posts[i].permalink + '">' + response.posts[i].title + '</a></h2>' +
									'<div class="meta">' + response.posts[i].date + response.posts[i].comments + '</div>' +
									'<div class="summary">' + response.posts[i].excerpt + '</div>' +
								'</div>' +
							'</article>'
						);
					}
					if (response.more) {
						latest_entries_offset += latest_entries_limit;
						jQuery('#<?php echo $args['widget_id']; ?> .load-more').removeClass('active');
					}
					else {
						latest_entries_offset = 0;
						jQuery('#<?php echo $args['widget_id']; ?> .load-more').hide();
					}
					if (scroll != false) scroll.loadMore();
				}
			});
		});
	});
	</script>

	<?php
	endif;

	echo $after_widget;
}

/**
 * Back-end widget form.
 *
 * @see WP_Widget::form()
 *
 * @param array $instance Previously saved values from database.
 */
public function form($instance) {
	if (isset($instance['title'])) $title = $instance['title'];
	else $title = __('Latest Entries', 'outspoken');
	if (isset($instance['limit'])) $limit = $instance['limit'];
	else $limit = 4;
	?>

	<p>
		<label for="<?php echo $this->get_field_name('title'); ?>"><?php _e('Title:', 'outspoken'); ?></label>
		<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" />
	</p>
	<p>
		<label for="<?php echo $this->get_field_name('limit'); ?>"><?php _e('How many items:', 'outspoken'); ?></label>
		<input class="widefat" id="<?php echo $this->get_field_id('limit'); ?>" name="<?php echo $this->get_field_name('limit'); ?>" type="text" value="<?php echo $limit; ?>" />
	</p>

	<?php
}

/**
 * Sanitize widget form values as they are saved.
 *
 * @see WP_Widget::update()
 *
 * @param array $new_instance Values just sent to be saved.
 * @param array $old_instance Previously saved values from database.
 *
 * @return array Updated safe values to be saved.
 */
public function update($new_instance, $old_instance) {
	$instance = array();
	$instance['title'] = !empty($new_instance['title']) ? strip_tags($new_instance['title']) : '';
	$instance['limit'] = !empty($new_instance['limit']) ? intval($new_instance['limit']) : 4;

	return $instance;
}

}
[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service