'napoli-magazine-grid-widget', 'description' => esc_html__( 'Displays your posts from a selected category in a grid layout.', 'napoli' ), 'customize_selective_refresh' => true, ) // Args. ); } /** * Set default settings of the widget */ private function default_settings() { $defaults = array( 'title' => esc_html__( 'Magazine (Grid)', 'napoli' ), 'category' => 0, 'layout' => 'three-columns', 'number' => 6, ); return $defaults; } /** * Main Function to display the widget * * @uses this->render() * * @param array $args / Parameters from widget area created with register_sidebar(). * @param array $instance / Settings for this widget instance. */ function widget( $args, $instance ) { // Start Output Buffering. ob_start(); // Get Widget Settings. $settings = wp_parse_args( $instance, $this->default_settings() ); // Set Widget class. $class = ( 'three-columns' === $settings['layout'] ) ? 'magazine-grid-three-columns' : 'magazine-grid-two-columns'; // Output. echo $args['before_widget']; ?>
magazine_posts_two_column_grid() or this->magazine_posts_three_column_grid() * @used-by this->widget() * * @param array $settings / Settings for this widget instance. */ function render( $settings ) { // Get cached post ids. $post_ids = napoli_get_magazine_post_ids( $this->id, $settings['category'], $settings['number'] ); // Fetch posts from database. $query_arguments = array( 'post__in' => $post_ids, 'posts_per_page' => absint( $settings['number'] ), 'ignore_sticky_posts' => true, 'no_found_rows' => true, ); $posts_query = new WP_Query( $query_arguments ); // Set template. $template = ( 'three-columns' === $settings['layout'] ) ? 'medium-post' : 'large-post'; // Check if there are posts. if ( $posts_query->have_posts() ) : // Display Posts. while ( $posts_query->have_posts() ) : $posts_query->the_post(); ?>
esc_html__( 'All Categories', 'napoli' ),
'show_count' => true,
'hide_empty' => false,
'selected' => $settings['category'],
'name' => $this->get_field_name( 'category' ),
'id' => $this->get_field_id( 'category' ),
);
wp_dropdown_categories( $args );
?>