WordPress.org

Ready to get started?Download WordPress

Forums

FP News Ticker
[resolved] Contribution (4 posts)

  1. ajberasategui
    Member
    Posted 10 months ago #

    Hey Flourish,

    I'm writing here as I dind't find any other way to contact you.

    Your plugin is great. I've extended it with a few lines of code to support "posts max age to include". If you want I can send you it, just contact me.

    Regards,
    Agus

    http://wordpress.org/plugins/fp-news-ticker/

  2. OGC
    Member
    Posted 10 months ago #

    Would you please post the code here? I think it would be very useful.

  3. ajberasategui
    Member
    Posted 10 months ago #

    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

  4. OGC
    Member
    Posted 9 months ago #

    thank you

Reply

You must log in to post.

About this Plugin

About this Topic

Tags

No tags yet.