Viewing 3 replies - 1 through 3 (of 3 total)
  • Would you please post the code here? I think it would be very useful.

    Thread Starter ajberasategui

    (@ajberasategui)

    Sure!

    1. Add to Widget form method:
    At the very beginning, where vars are read,
    $max_age = $instance['max_age'];
    and in the html form:

    <p class="fp_label">
      <label for="<?php echo $this->get_field_id('max_age'); ?>">Max Age:
        <input class="custom" id="<?php echo $this->get_field_id('max_age'); ?>" name="<?php echo $this->get_field_name('max_age'); ?>" type="text" value="<?php echo attribute_escape($max_age); ?>" />
      </label>
    </p>

    2. Add to Widget update method:
    $instance['max_age'] = $new_instance['max_age'];

    3. Replace in Widget widget method:
    query_posts( 'cat='.$category.'&showposts='.$limit );
    with

    function filter_post_time( $where = '' ) {
    		global $max_age;
    		if ( '' != $max_age )
    			$where .= " AND DATE_SUB(NOW(), INTERVAL ". $max_age ." HOUR) <= post_date";
    		return $where;
    	}
    
    	$GLOBALS['max_age'] = $max_age;
    	add_filter( 'posts_where', 'filter_post_time' );
    	query_posts( 'cat='.$category.'&showposts='.$limit );
    	remove_filter( 'posts_where', 'filter_post_time' );

    that is, before the widget method posts loop.
    And add at the begining of this method, where vars are set,
    $max_age = empty($instance['limit']) ? '' : $instance['max_age'];

    Hope you find it useful!

    Agus

    thank you

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Contribution’ is closed to new replies.