D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
proc
/
thread-self
/
root
/
proc
/
self
/
cwd
/
wp-content
/
plugins
/
aeen-core
/
widgets
/
Filename :
practice-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 Practice_Post_Widget extends WP_Widget { public function __construct() { $id = AEEN_CORE_THEME_PREFIX . '_practice_post'; parent::__construct( $id, // Base ID esc_html__( 'A3: Practice Posts', 'aeen-core' ), // Name array( 'description' => esc_html__( 'Aeen: Practice Posts Widget', 'aeen-core' ) ) ); } public function widget( $args, $instance ){ echo wp_kses_post( $args['before_widget'] ); $current_post = get_the_ID(); if ( ! empty( $instance['title'] ) ) { echo wp_kses_post( $args['before_title'] ) . apply_filters( 'widget_title', esc_html( $instance['title'] ) ) . wp_kses_post( $args['after_title'] ); } if (!empty($instance['title'])) { $title = $instance['title']; } else { $title = ''; } $q_args = array( 'post_type' => 'aeen_practice', 'post_status' => 'publish', '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() ) : ?> <ul class="widget-practice"> <?php while ( $query->have_posts() ) : $query->the_post(); if ($current_post === get_the_ID()) { $active = 'active'; } else { $active = ''; } ?> <li class="single-item"> <a href="<?php the_permalink(); ?>" class="<?php echo esc_attr( $active ); ?>"><?php the_title(); ?></a> </li> <?php endwhile; ?> </ul> <?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['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' => '', 'orderby' => '', 'number' => '4', ); $instance = wp_parse_args( (array) $instance, $defaults ); $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', ), '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 ); } }