Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- if ( ! defined( 'ABSPATH' ) ) {
- exit;
- }
- /**
- * RT List Page Widget.
- *
- * Show list pages.
- *
- * @author NamNCN
- * @category Widgets
- * @package RTCORE/Widgets
- * @version 1.0.0
- * @extends RT_Widget
- */
- class RT_List_Page_Widget extends RT_Widget {
- /**
- * Constructor.
- */
- public function __construct() {
- $this->widget_cssclass = 'rt_list_page_widget';
- $this->widget_description = esc_html__( "Hiển thị các trang.", 'raothue' );
- $this->widget_id = 'rt_list_page_widget';
- $this->widget_name = esc_html__( 'RT: Danh sách Trang', 'raothue' );
- $this->settings = array(
- 'title' => array(
- 'type' => 'text',
- 'label' => esc_html__( 'Tiêu đề', 'raothue' ),
- 'std' => esc_html__( 'Danh sách Trang', 'raothue' ),
- ),
- 'number' => array(
- 'type' => 'text',
- 'std' => 1,
- 'label' => esc_html__( 'Số trang muốn hiển thị:', 'raothue' ),
- 'desc' => esc_html__( 'Điền -1 để hiển thị tất cả bài viết', 'raothue' ),
- ),
- 'include' => array(
- 'type' => 'text',
- 'std' => '',
- 'label' => esc_html__( 'Chọn trang muốn hiển thị', 'raothue' ),
- ),
- );
- parent::__construct();
- }
- /**
- * Output widget.
- *
- * @see WP_Widget
- *
- * @param array $args
- * @param array $instance
- */
- public function widget( $args, $instance ) {
- // extract( $instance ); Don't extract variable $args, $instance cuz its not work when selective refresh.
- $defaults = array(
- 'number' => 1,
- 'include' => '',
- );
- $instance = wp_parse_args( $instance, $defaults );
- var_dump( $instance['include'] );
- $post_args = array(
- 'post_type' => 'page',
- 'posts_per_page' => $instance['number'],
- 'ignore_sticky_posts' => true,
- 'post__in' => array( $instance['include'] ),
- );
- $post_query = new WP_Query( $post_args );
- $this->widget_start( $args, $instance );
- if ( $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base ) ) {
- echo $args['before_title'] . $title . $args['after_title'];
- }
- if ( $post_query->have_posts() ) : ?>
- <div class="rt__list_page clearfix">
- <?php while ( $post_query->have_posts() ) : $post_query->the_post(); ?>
- <div class="list_item">
- <?php if ( has_post_thumbnail() ) : ?>
- <div class="list_item-thumbnail">
- <a href="<?php the_permalink(); ?>">
- <?php the_post_thumbnail( 'medium' ); ?>
- </a>
- </div>
- <?php endif; ?>
- <div class="list_item-details">
- <?php the_title( '<a href="' . get_the_permalink() . '">', '</a>' ); ?>
- </div><!-- .list_item-details -->
- </div><!-- .list_item -->
- <?php endwhile; ?>
- </div><!-- .list__items -->
- <?php wp_reset_postdata();
- endif;
- $this->widget_end( $args );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement