D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
home
/
etb1lp46s9ed
/
public_html
/
a3legalservices.site
/
wp-content
/
plugins
/
aeen-core
/
widgets
/
Filename :
post.php
back
Copy
<?php /** * @author RadiusTheme * @since 1.0 * @version 1.0 */ namespace radiustheme\Aeen_Core; use \WP_Widget; use \RT_Widget_Fields; use radiustheme\Aeen\Helper; class Post_Widget extends WP_Widget { public function __construct() { $id = AEEN_CORE_THEME_PREFIX . '_post'; parent::__construct( $id, // Base ID esc_html__( 'Aeen: Posts', 'aeen-core' ), // Name array( 'description' => esc_html__( 'Aeen: Posts Widget', 'aeen-core' ) ) ); } public function widget( $args, $instance ){ echo wp_kses_post( $args['before_widget'] ); 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)) { ?> <div class="widget-section-heading heading-dark"> <h4 class="item-heading"><?php echo esc_html( $title ); ?></h4> </div> <?php } ?> <ul class="widget-recent-post aeen-recent-post"> <?php while ( $query->have_posts() ) : $query->the_post();?> <li class="single-item"> <div class="left-box"> <a href="<?php the_permalink(); ?>" class="item-figure"> <?php the_post_thumbnail( 'thumbnail' ); ?> </a> </div> <div class="right-box"> <div class="post-date"> <i class="far fa-calendar-alt"></i><?php the_time( get_option( 'date_format' ) ); ?> </div> <div class="entry-title"><h5><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h5></div> </div> </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'] ) : ''; return $instance; } public function form( $instance ){ $defaults = array( 'title' => '', 'cat' => '0', 'orderby' => '', 'number' => '4', ); $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', ), ); RT_Widget_Fields::display( $fields, $instance, $this ); } }