Advertisement
Guest User

Untitled

a guest
Apr 24th, 2017
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.92 KB | None | 0 0
  1. <?php
  2.  
  3. if ( ! defined( 'ABSPATH' ) ) {
  4.     exit;
  5. }
  6.  
  7. /**
  8.  * RT List Page Widget.
  9.  *
  10.  * Show list pages.
  11.  *
  12.  * @author   NamNCN
  13.  * @category Widgets
  14.  * @package  RTCORE/Widgets
  15.  * @version  1.0.0
  16.  * @extends  RT_Widget
  17.  */
  18. class RT_List_Page_Widget extends RT_Widget {
  19.  
  20.     /**
  21.      * Constructor.
  22.      */
  23.     public function __construct() {
  24.         $this->widget_cssclass    = 'rt_list_page_widget';
  25.         $this->widget_description = esc_html__( "Hiển thị các trang.", 'raothue' );
  26.         $this->widget_id          = 'rt_list_page_widget';
  27.         $this->widget_name        = esc_html__( 'RT: Danh sách Trang', 'raothue' );
  28.         $this->settings           = array(
  29.             'title'  => array(
  30.                 'type'  => 'text',
  31.                 'label' => esc_html__( 'Tiêu đề', 'raothue' ),
  32.                 'std'   => esc_html__( 'Danh sách Trang', 'raothue' ),
  33.             ),
  34.             'number' => array(
  35.                 'type'   => 'text',
  36.                 'std'    => 1,
  37.                 'label'  => esc_html__( 'Số trang muốn hiển thị:', 'raothue' ),
  38.                 'desc'   => esc_html__( 'Điền -1 để hiển thị tất cả bài viết', 'raothue' ),
  39.             ),
  40.             'include' => array(
  41.                 'type'  => 'text',
  42.                 'std'   => '',
  43.                 'label' => esc_html__( 'Chọn trang muốn hiển thị', 'raothue' ),
  44.             ),
  45.         );
  46.  
  47.         parent::__construct();
  48.     }
  49.  
  50.     /**
  51.      * Output widget.
  52.      *
  53.      * @see WP_Widget
  54.      *
  55.      * @param array $args
  56.      * @param array $instance
  57.      */
  58.     public function widget( $args, $instance ) {
  59.  
  60.         // extract( $instance ); Don't extract variable $args, $instance cuz its not work when selective refresh.
  61.         $defaults = array(
  62.             'number'         => 1,
  63.             'include'            => '',
  64.         );
  65.  
  66.         $instance = wp_parse_args( $instance, $defaults );
  67.  
  68.         var_dump( $instance['include'] );
  69.  
  70.         $post_args = array(
  71.             'post_type' => 'page',
  72.             'posts_per_page'       => $instance['number'],
  73.             'ignore_sticky_posts'  => true,
  74.             'post__in' => array( $instance['include'] ),
  75.         );
  76.  
  77.         $post_query = new WP_Query( $post_args );
  78.  
  79.         $this->widget_start( $args, $instance );
  80.  
  81.         if ( $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base ) ) {
  82.  
  83.             echo $args['before_title'] . $title . $args['after_title'];
  84.  
  85.         }
  86.  
  87.         if ( $post_query->have_posts() ) : ?>
  88.  
  89.             <div class="rt__list_page clearfix">
  90.  
  91.             <?php while ( $post_query->have_posts() ) : $post_query->the_post(); ?>
  92.  
  93.                 <div class="list_item">
  94.  
  95.                     <?php if ( has_post_thumbnail() ) : ?>
  96.  
  97.                     <div class="list_item-thumbnail">
  98.  
  99.                         <a href="<?php the_permalink(); ?>">
  100.                             <?php the_post_thumbnail( 'medium' ); ?>
  101.                         </a>
  102.  
  103.                     </div>
  104.  
  105.                     <?php endif; ?>
  106.  
  107.                     <div class="list_item-details">
  108.  
  109.                         <?php the_title( '<a href="' . get_the_permalink() . '">', '</a>' ); ?>
  110.  
  111.                     </div><!-- .list_item-details -->
  112.  
  113.                 </div><!-- .list_item -->
  114.  
  115.             <?php endwhile; ?>
  116.  
  117.             </div><!-- .list__items -->
  118.  
  119.             <?php wp_reset_postdata();
  120.         endif;
  121.  
  122.         $this->widget_end( $args );
  123.     }
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement