Guest User

Untitled

a guest
Aug 12th, 2015
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.77 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Home: Recent Listings
  4.  *
  5.  * @since Listify 1.0.0
  6.  */
  7. class Listify_Widget_Recent_Listings extends Listify_Widget {
  8.  
  9.     /**
  10.      * Constructor
  11.      */
  12.     public function __construct() {
  13.         $this->widget_description = __( 'Display a grid of recent or featured listings', 'listify' );
  14.         $this->widget_id          = 'listify_widget_recent_listings';
  15.         $this->widget_name        = __( 'Listify - Page: Recent Listings', 'listify' );
  16.         $this->settings           = array(
  17.             'title' => array(
  18.                 'type'  => 'text',
  19.                 'std'   => 'Recent Listings',
  20.                 'label' => __( 'Title:', 'listify' )
  21.             ),
  22.             'description' => array(
  23.                 'type'  => 'text',
  24.                 'std'   => 'Discover some of our best listings',
  25.                 'label' => __( 'Description:', 'listify' )
  26.             ),
  27.             'featured' => array(
  28.                 'type'  => 'checkbox',
  29.                 'std'   => 0,
  30.                 'label' => __( 'Show only featured listings', 'listify' )
  31.             ),
  32.             'orderby' => array(
  33.                 'type'  => 'checkbox',
  34.                 'std'   => 0,
  35.                 'label' => __( 'Randomize display', 'listify' )
  36.             ),
  37.             'limit' => array(
  38.                 'type'  => 'number',
  39.                 'std'   => 3,
  40.                 'min'   => 3,
  41.                 'max'   => 30,
  42.                 'step'  => 3,
  43.                 'label' => __( 'Number to show:', 'listify' )
  44.             ),
  45.         );
  46.         parent::__construct();
  47.     }
  48.  
  49.     /**
  50.      * widget function.
  51.      *
  52.      * @see WP_Widget
  53.      * @access public
  54.      * @param array $args
  55.      * @param array $instance
  56.      * @return void
  57.      */
  58.     function widget( $args, $instance ) {
  59.         if ( $this->get_cached_widget( $args ) )
  60.             return;
  61.  
  62.         extract( $args );
  63.  
  64.         $title = apply_filters( 'widget_title', $instance[ 'title' ], $instance, $this->id_base );
  65.         $description = isset( $instance[ 'description' ] ) ? esc_attr( $instance[ 'description' ] ) : false;
  66.         $featured = isset( $instance[ 'featured' ] ) && 1 == $instance[ 'featured' ] ? true : null;
  67.         $orderby = isset($instance['orderby']) && 1 == $instance['orderby'] ? 'rand' : null;
  68.         $limit = isset( $instance[ 'limit' ] ) ? absint( $instance[ 'limit' ] ) : 3;
  69.  
  70.         $after_title = '<h2 class="home-widget-description">' . $description . '</h2>' . $after_title;
  71.  
  72.         $listings = get_job_listings( array(
  73.             'posts_per_page' => $limit,
  74.             'featured' => $featured,
  75.             'orderby' => $orderby,
  76.             'no_found_rows' => true
  77.         ) );
  78.  
  79.         if ( ! $listings->have_posts() ) {
  80.             return;
  81.         }
  82.  
  83.         ob_start();
  84.  
  85.         echo $before_widget;
  86.  
  87.         if ( $title ) echo $before_title . $title . $after_title;
  88.         ?>
  89.  
  90.         <ul class="job_listings">
  91.             <?php while ( $listings->have_posts() ) : $listings->the_post(); ?>
  92.  
  93.                 <?php get_template_part( 'content', 'job_listing' ); ?>
  94.  
  95.             <?php endwhile; ?>
  96.         </ul>
  97.  
  98.         <?php
  99.         echo $after_widget;
  100.        
  101.         wp_reset_postdata();
  102.  
  103.         $content = ob_get_clean();
  104.  
  105.         echo apply_filters( $this->widget_id, $content );
  106.  
  107.         $this->cache_widget( $args, $content );
  108.     }
  109. }
Advertisement
Add Comment
Please, Sign In to add comment