Submit
Path:
~
/
home
/
getwphos
/
www
/
chemex
/
wp-content
/
plugins
/
poolax-core
/
inc
/
widgets
/
File Content:
recent-post-widget.php
<?php /** * @version 1.0 * @package poolax * @author Themeholy <themeholy@gmail.com> * * Websites: https://themeholy.com/ * */ /************************************** * Creating Recent Post Widget ***************************************/ class poolax_recent_posts_widget extends WP_Widget { function __construct() { parent::__construct( // Base ID of your widget 'poolax_recent_posts_widget', // Widget name will appear in UI esc_html__( 'Poolax :: Recent Posts', 'poolax' ), // Widget description array( 'classname' => '', 'customize_selective_refresh' => true, 'description' => esc_html__( 'Add Recent Posts Widget', 'poolax' ), ) ); } // This is where the action happens public function widget( $args, $instance ) { $title = apply_filters( 'widget_title', $instance['title'] ); $show_date = isset( $instance['show_date'] ) ? $instance['show_date'] : false; //Post Count if ( isset( $instance[ 'post_count' ] ) ) { $post_count = $instance[ 'post_count' ]; }else { $post_count = '4'; } //Post title Count if ( isset( $instance[ 'post_title_count' ] ) ) { $post_title_count = $instance[ 'post_title_count' ]; }else { $post_title_count = '5'; } //Post Box Class if ( isset( $instance[ 'post_box_class' ] ) ) { $post_box_class = $instance[ 'post_box_class' ]; }else { $post_box_class = ''; } $post_img_size = isset( $instance[ 'post_img_size' ] ) ? $instance[ 'post_img_size' ] : 'poolax_85X85'; //before and after widget arguments are defined by themes // echo $args['before_widget']; echo '<div class="widget '.$post_box_class.'">'; if( !empty( $title ) ){ echo '<h3 class="widget_title">'.esc_html( $title ).'</h3>'; } $query_args = array( "post_type" => "post", "posts_per_page" => esc_attr( $post_count ), "post_status" => "publish", "ignore_sticky_posts" => true, ); $recentposts = new WP_Query( $query_args ); if( $recentposts->have_posts( ) ) { echo '<div class="recent-post-wrap">'; while( $recentposts->have_posts( ) ) { $recentposts->the_post(); echo '<div class="recent-post">'; if( has_post_thumbnail() ){ echo '<div class="media-img">'; echo '<a href="'.get_the_permalink().'">'; echo poolax_img_tag( array( "url" => esc_url( get_the_post_thumbnail_url( null, $post_img_size ) ), ) ); echo '</a>'; echo '</div>'; } echo '<div class="media-body">'; echo '<h4 class="post-title">'; echo '<a class="text-inherit" href="'.esc_url( get_the_permalink() ).'">'.wp_trim_words( wp_kses_post( get_the_title() ), $post_title_count, '' ).'</a>'; echo '</h4>'; echo '<div class="recent-post-meta">'; if($show_date){ echo '<a href="'.esc_url( get_the_permalink() ).'"><i class="far fa-calendar-days"></i>'.esc_html( get_the_time( 'd M Y' ) ).'</a>'; } echo '</div>'; echo '</div>'; echo '</div>'; wp_reset_postdata(); } echo '</div>'; } echo '</div>'; // echo $args['after_widget']; } // Widget Backend public function form( $instance ) { //Title if ( isset( $instance[ 'title' ] ) ) { $title = $instance[ 'title' ]; }else { $title = ''; } //Post Count if ( isset( $instance[ 'post_count' ] ) ) { $post_count = $instance[ 'post_count' ]; }else { $post_count = '3'; } //Post title Count if ( isset( $instance[ 'post_title_count' ] ) ) { $post_count = $instance[ 'post_title_count' ]; }else { $post_count = '5'; } // Show Date $show_date = isset( $instance['show_date'] ) ? (bool) $instance['show_date'] : false; //Post Box Class if ( isset( $instance[ 'post_box_class' ] ) ) { $post_box_class = $instance[ 'post_box_class' ]; }else { $post_box_class = ''; } $post_img_size = isset( $instance[ 'post_img_size' ] ) ? $instance[ 'post_img_size' ] : 'poolax_85X85'; // Widget admin form ?> <p> <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ,'poolax'); ?></label> <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" /> </p> <p> <label for="<?php echo $this->get_field_id( 'post_count' ); ?>"><?php _e( 'Number of Posts to show:' ,'poolax'); ?></label> <input class="widefat" id="<?php echo $this->get_field_id( 'post_count' ); ?>" name="<?php echo $this->get_field_name( 'post_count' ); ?>" type="text" value="<?php echo esc_attr( $post_count ); ?>" /> </p> <p> <label for="<?php echo $this->get_field_id( 'post_title_count' ); ?>"><?php _e( 'Number of title word to show:' ,'poolax'); ?></label> <input class="widefat" id="<?php echo $this->get_field_id( 'post_title_count' ); ?>" name="<?php echo $this->get_field_name( 'post_title_count' ); ?>" type="text" value="<?php echo esc_attr( $post_title_count ); ?>" /> </p> <p> <input class="checkbox" type="checkbox"<?php checked( $show_date ); ?> id="<?php echo $this->get_field_id( 'show_date' ); ?>" name="<?php echo $this->get_field_name( 'show_date' ); ?>" /> <label for="<?php echo $this->get_field_id( 'show_date' ); ?>"><?php _e( 'Display post Date?' ); ?></label> </p> <p> <label for="<?php echo $this->get_field_id( 'post_box_class' ); ?>"><?php _e( 'Box Extra Class:' ,'poolax'); ?></label> <input class="widefat" id="<?php echo $this->get_field_id( 'post_box_class' ); ?>" name="<?php echo $this->get_field_name( 'post_box_class' ); ?>" type="text" value="<?php echo esc_attr( $post_box_class ); ?>" /> </p> <p> <label for="<?php echo $this->get_field_id( 'post_img_size' ); ?>"><?php _e( 'Post Image Size:' ,'poolax'); ?></label> <input class="widefat" id="<?php echo $this->get_field_id( 'post_img_size' ); ?>" name="<?php echo $this->get_field_name( 'post_img_size' ); ?>" type="text" value="<?php echo esc_attr( $post_img_size ); ?>" /> </p> <?php } // Updating widget replacing old instances with new public function update( $new_instance, $old_instance ) { $instance = array(); $instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : ''; $instance['post_count'] = ( ! empty( $new_instance['post_count'] ) ) ? strip_tags( $new_instance['post_count'] ) : '4'; $instance['post_title_count'] = ( ! empty( $new_instance['post_title_count'] ) ) ? strip_tags( $new_instance['post_title_count'] ) : '5'; $instance['show_date'] = isset( $new_instance['show_date'] ) ? (bool) $new_instance['show_date'] : false; $instance['post_box_class'] = ( ! empty( $new_instance['post_box_class'] ) ) ? strip_tags( $new_instance['post_box_class'] ) : ''; $instance['post_img_size'] = ( ! empty( $new_instance['post_img_size'] ) ) ? strip_tags( $new_instance['post_img_size'] ) : ''; return $instance; } } // Class poolax_recent_posts_widget ends here // Register and load the widget function poolax_recent_posts_load_widget() { register_widget( 'poolax_recent_posts_widget' ); } add_action( 'widgets_init', 'poolax_recent_posts_load_widget' );
Submit
FILE
FOLDER
Name
Size
Permission
Action
about-us-widget.php
7369 bytes
0644
author-widget.php
6120 bytes
0644
categories-lists.php
4327 bytes
0644
offer-banner.php
9403 bytes
0644
recent-post-widget.php
9627 bytes
0644
search-form.php
3144 bytes
0644
N4ST4R_ID | Naxtarrr