* @copyright Copyright 2014, Chris Aprea * @link http://wpaxl.com/themes/adoration * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html */ // Exit if accessed directly defined( 'ABSPATH' ) || exit; class Adoration_Widget_Recent_Posts extends Adoration_Widget { /** * Constructor */ public function __construct() { $this->widget_cssclass = 'widget_adoration_recent_entries'; $this->widget_description = esc_html__( 'Your site’s most recent Posts.', 'adoration' ); $this->widget_id = 'adoration_recent_posts'; $this->widget_name = esc_html__( 'Adoration Recent Posts', 'adoration' ); $this->settings = array( 'title' => array( 'type' => 'text', 'std' => esc_html__( 'Recent Posts', 'adoration' ), 'label' => esc_html__( 'Title', 'adoration' ) ), 'number' => array( 'type' => 'number', 'step' => 1, 'min' => 1, 'max' => '', 'std' => 5, 'label' => esc_html__( 'Number of posts to show', 'adoration' ) ), 'show_date' => array( 'type' => 'checkbox', 'std' => 0, 'label' => __( 'Display post date', 'adoration' ) ), ); parent::__construct(); } /** * Widget function. * * @since 1.0.0 * @see WP_Widget * @param array $args * @param array $instance */ public function widget( $args, $instance ) { global $comments, $comment; // Allow developers to short-circuit this function. $pre = apply_filters( 'adoration_pre_recent_posts', false, $args, $instance ); if ( false !== $pre ) { echo $pre; return; } if ( $this->get_cached_widget( $args ) ) { return; } $number = ( ! empty( $instance['number'] ) ) ? absint( $instance['number'] ) : 5; if ( ! $number ) { $number = 5; } $show_date = isset( $instance['show_date'] ) ? $instance['show_date'] : false; /** * Filter the arguments for the Recent Posts widget. * * @since 1.0.0 * @see WP_Query::get_posts() * @param array $args An array of arguments used to retrieve the recent posts. */ $r = new WP_Query( apply_filters( 'adoration_widget_posts_args', array( 'posts_per_page' => $number, 'no_found_rows' => true, 'post_status' => 'publish', 'ignore_sticky_posts' => true ) ) ); if ( ! $r->have_posts() ) { $this->cache_widget( $args, '' ); return; } ob_start(); $this->widget_start( $args, $instance ); ?> widget_end( $args ); $content = ob_get_clean(); echo $content; $this->cache_widget( $args, $content ); } }