__( 'Display a list of Recent or Random posts in a timeline format.' , 'amazing-widgets') )
);
}
public function form( $instance ) {
$defaults = array(
'title' => '',
'what_to_query' => 'random_posts',
'category' => '',
'nr_of_posts' => 4
);
$instance = wp_parse_args( (array) $instance, $defaults );
?>
post_author;
printf(esc_attr__('By %1$s on %2$s','aw-widgets'), get_the_author_meta( 'display_name', $post->post_author ), get_the_date());
}
echo $args['before_widget'];
if ( ! empty( $instance['title'] ) ) {
echo $args['before_title'];
echo esc_html( $instance['title'] );
echo $args['after_title'];
}
echo " \n";
if( false === ( $wp_query = get_transient( 'aw_random_recent' ) ) ) {
$wp_query = new WP_Query(
array(
'cat' => $instance['category'],
'orderby' => $instance['what_to_query'],
'posts_per_page' => $instance['nr_of_posts']
)
);
set_transient( 'aw_random_recent', $wp_query, 4 * HOUR_IN_SECONDS );
}
while ( $wp_query->have_posts() ) : $wp_query->the_post();
?>
-
'alignright' ) ); ?>
\n";
echo $args['after_widget'];
}
}
// Register the widget
add_action('widgets_init',
create_function('', 'return register_widget("AW_Random_Widget");')
);
if ( ! function_exists( 'aw_delete_random_recent' ) ) {
add_action( 'save_post', 'aw_delete_random_recent' );
function aw_delete_random_recent() {
delete_transient( 'aw_random_recent' );
}
}