So.. Im having a widget from ET that I have changed so it shows random posts. But since I have change they way Im writing in my posts I only want to show posts that are written after 1th January 2013. Can someone pls help me with this. I have been trying for ever to find help for this. I paste my code here. Also, Im not using any boxes or anything like that on the widget, just the code here.
<?php class PopularWidget extends WP_Widget
{
function PopularWidget(){
$widget_ops = array('description' => 'Displays Popular Posts');
$control_ops = array('width' => 400, 'height' => 300);
parent::WP_Widget(false,$name='ET Popular Widget',$widget_ops,$control_ops);
}
/* Displays the Widget in the front-end */
function widget($args, $instance){
extract($args);
$title = apply_filters('widget_title', empty($instance['title']) ? 'Popular This Week' : $instance['title']);
$postsNum = empty($instance['postsNum']) ? '' : (int) $instance['postsNum'];
$show_thisweek = isset($instance['thisweek']) ? (bool) $instance['thisweek'] : false;
echo $before_widget;
if ( $title )
echo $before_title . $title . $after_title;
?>
<?php
$additional_query = $show_thisweek ? '&year=' . date('Y') . '&w=' . date('W') : '';
query_posts( 'post_type=post&posts_per_page='.$postsNum.'&orderby=rand' . $additional_query ); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class="blog-entry">
<a>" class="comments"></a>
<h4 class="title"><a>"><?php the_title(); ?></a></h4>
<p class="meta-info"><?php the_time('j F Y'); ?></p>
</div>
<?php endwhile; endif; wp_reset_query(); ?>
<?php
echo $after_widget;
}
/*Saves the settings. */
function update($new_instance, $old_instance){
$instance = $old_instance;
$instance['title'] = sanitize_text_field($new_instance['title']);
$instance['postsNum'] = (int) $new_instance['postsNum'];
$instance['thisweek'] = 0;
if ( isset($new_instance['thisweek']) ) $instance['thisweek'] = 1;
return $instance;
}
/*Creates the form for the widget in the back-end. */
function form($instance){
//Defaults
$instance = wp_parse_args( (array) $instance, array('title'=>'Popular Posts', 'postsNum'=>'','thisweek'=>false) );
$title = $instance['title'];
$postsNum = (int) $instance['postsNum'];
# Title
echo '<p><label for="' . $this->get_field_id('title') . '">' . 'Title:' . '</label><input class="widefat" id="' . $this->get_field_id('title') . '" name="' . $this->get_field_name('title') . '" type="text" value="' . esc_attr( $title ) . '" /></p>';
# Number of posts
echo '<p><label for="' . $this->get_field_id('postsNum') . '">' . 'Number of posts:' . '</label><input class="widefat" id="' . $this->get_field_id('postsNum') . '" name="' . $this->get_field_name('postsNum') . '" type="text" value="' . esc_attr( $postsNum ) . '" /></p>'; ?>
<input class="checkbox" type="checkbox" <?php checked($instance['thisweek'], 1) ?> id="<?php echo $this->get_field_id('thisweek'); ?>" name="<?php echo $this->get_field_name('thisweek'); ?>" />
<label for="<?php echo $this->get_field_id('thisweek'); ?>"><?php esc_html_e('Popular this week','Aggregate'); ?></label>
<?php
}
}// end AboutMeWidget class
function PopularWidgetInit() {
register_widget('PopularWidget');
}
add_action('widgets_init', 'PopularWidgetInit');
?>
[Moderator Note: Please post code & markup between backticks or use the code button. Your posted code may now have been permanently damaged by the forum's parser.]