D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
proc
/
self
/
root
/
proc
/
self
/
cwd
/
wp-content
/
plugins
/
aeen-core
/
widgets
/
Filename :
footer-post.php
back
Copy
<?php /** * @author RadiusTheme * @since 1.0 * @version 1.0 */ namespace radiustheme\Aeen_Core; use \WP_Widget; use \RT_Widget_Fields; class Footer_Post_Widget extends WP_Widget { public function __construct() { $id = AEEN_CORE_THEME_PREFIX . '_footer_post'; parent::__construct( $id, // Base ID esc_html__( 'Aeen: Footer Posts', 'aeen-core' ), // Name array( 'description' => esc_html__( 'Aeen: Footer Posts Widget', 'aeen-core' ) ) ); } public function widget( $args, $instance ){ echo wp_kses_post( $args['before_widget'] ); $title_length = !empty( ( $instance['title_length'] ) ) ? $instance['title_length'] : 5 ; if (!empty($instance['title'])) { $title = $instance['title']; } else { $title = ''; } $q_args = array( 'cat' => (int) $instance['cat'], 'orderby' => $instance['orderby'], 'posts_per_page' => $instance['number'], 'ignore_sticky_posts' => true, ); switch ( $instance['orderby'] ){ case 'title': case 'menu_order': $q_args['order'] = 'ASC'; break; } $query = new \WP_Query( $q_args ); ?> <?php if ( $query->have_posts() ) :?> <div class="widget"> <?php if (!empty($title)) { ?> <h3 class="footer-widget-heading"><?php echo esc_html( $title ); ?></h3> <?php } ?> <ul class="blog-latest-news"> <?php while ( $query->have_posts() ) : $query->the_post();?> <li> <a href="<?php the_permalink(); ?>"> <?php if( has_post_thumbnail( ) ) : ?> <div class="blog-thumb"> <?php the_post_thumbnail( 'aeen-thumb-size2' ); ?> </div> <?php endif; ?> <div class="blog-content"> <h4 class="blog-title"><?php echo wp_trim_words( get_the_title(), $title_length ); ?></h4> <span class="blog-post-date"><?php the_time( get_option( 'date_format' ) ); ?></span> </div> </a> </li> <?php endwhile;?> </ul> </div> <?php else: ?> <div><?php esc_html_e( 'Currently there are no posts to display', 'aeen-core' ); ?></div> <?php endif;?> <?php wp_reset_postdata();?> <?php echo wp_kses_post( $args['after_widget'] ); } public function update( $new_instance, $old_instance ){ $instance = array(); $instance['title'] = ( ! empty( $new_instance['title'] ) ) ? sanitize_text_field( $new_instance['title'] ) : ''; $instance['cat'] = ( ! empty( $new_instance['cat'] ) ) ? sanitize_text_field( $new_instance['cat'] ) : ''; $instance['orderby'] = ( ! empty( $new_instance['orderby'] ) ) ? sanitize_text_field( $new_instance['orderby'] ) : ''; $instance['number'] = ( ! empty( $new_instance['number'] ) ) ? sanitize_text_field( $new_instance['number'] ) : ''; $instance['title_length'] = ( ! empty( $new_instance['title_length'] ) ) ? sanitize_text_field( $new_instance['title_length'] ) : ''; return $instance; } public function form( $instance ){ $defaults = array( 'title' => '', 'cat' => '0', 'orderby' => '', 'number' => '3', 'title_length' => '5', ); $instance = wp_parse_args( (array) $instance, $defaults ); $categories = get_categories(); $category_dropdown = array( '0' => __( 'All Categories', 'aeen-core' ) ); foreach ( $categories as $category ) { $category_dropdown[$category->term_id] = $category->name; } $orderby = array( 'date' => __( 'Date (Recents comes first)', 'aeen-core' ), 'title' => __( 'Title', 'aeen-core' ), 'menu_order' => __( 'Custom Order (Available via Order field inside Page Attributes box)', 'aeen-core' ), ); $fields = array( 'title' => array( 'label' => esc_html__( 'Title', 'aeen-core' ), 'type' => 'text', ), 'cat' => array( 'label' => esc_html__( 'Category', 'aeen-core' ), 'type' => 'select', 'options' => $category_dropdown, ), 'orderby' => array( 'label' => esc_html__( 'Order by', 'aeen-core' ), 'type' => 'select', 'options' => $orderby, ), 'number' => array( 'label' => esc_html__( 'Number of Post', 'aeen-core' ), 'type' => 'number', ), 'title_length' => array( 'label' => esc_html__( 'Title Length', 'aeen-core' ), 'type' => 'number', ), ); RT_Widget_Fields::display( $fields, $instance, $this ); } }