advantage_Recent_Post

Advantage Theme Widgets.

Defined (1)

The class is defined in the following location(s).

/inc/widgets.php  
  1. class advantage_Recent_Post extends WP_Widget { 
  2. function __construct() { 
  3. WP_Widget::__construct( 
  4. 'widget_advantage_recent_post',  
  5. __( '(advantage) Recent Posts', 'advantage' ),  
  6. array( 
  7. 'classname' => 'advantage_recent_post',  
  8. 'description' => __( 'Use this widget to list your recent post summary.', 'advantage' ),  
  9. ); 
  10. // Widget outputs 
  11. function widget( $args, $instance ) { 
  12. extract( $args, EXTR_SKIP ); 
  13. $instance = wp_parse_args($instance, $this->widget_defaults()); 
  14. extract( $instance, EXTR_SKIP ); 
  15. $title = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base); 
  16.  
  17. if ( $random_post ) 
  18. $sortby = 'rand'; 
  19. else 
  20. $sortby = ''; 
  21. if ( $sticky_post ) 
  22. $sticky = array(); 
  23. else 
  24. $sticky = get_option( 'sticky_posts' ); 
  25.  
  26. global $advantage_display_excerpt, $advantage_entry_meta; 
  27. $advantage_display_excerpt = $display_excerpt; 
  28. $advantage_entry_meta = $entry_meta; 
  29.  
  30. $query_str = array( 
  31. 'order' => 'DESC',  
  32. 'orderby' => $sortby,  
  33. 'posts_per_page' => $number,  
  34. 'post_status' => 'publish',  
  35. 'post_type' => $posttype,  
  36. 'ignore_sticky_posts' => 1,  
  37. 'no_found_rows' => 1,  
  38. ); 
  39. if ( 'post' == $posttype ) { 
  40. $query_str['category__in'] = $category; 
  41. $query_str['post__not_in'] = $sticky;  
  42. if ( ! empty( $customquery ) ) { 
  43. $custom_query = wp_parse_args( $customquery, NULL );  
  44. foreach ( $custom_query as $key => $query ) { 
  45. if ( strpos( $key, '__' ) && strpos( $query, ', ' ) ) 
  46. $query_str[$key] = explode( ', ', $query );  
  47. else 
  48. $query_str[$key] = $query; 
  49.  
  50. $recent_posts = new WP_Query( $query_str ); 
  51. if ( $recent_posts->have_posts() ) : 
  52. echo $before_widget;  
  53.  
  54. if ( ! empty( $title ) ) { 
  55. echo $before_title; 
  56. echo $title; // Can set this with a widget option, or omit altogether 
  57. echo $after_title;  
  58. if ( ! empty( $category_link ) && $category ) { 
  59.  
  60. printf( '<a href="%1$s" title="%2$s" class="recent_post_link btn btn-small btn-transparent">%3$s</a>',  
  61. get_category_link( $category ) ,  
  62. get_the_category_by_ID( $category ),  
  63. $category_link );  
  64. }  
  65.  
  66. global $advantage_thumbnail; 
  67.  
  68. $advantage_thumbnail = advantage_thumbnail_size( $thumbnail, $thumbnail_x, $thumbnail_y); 
  69. $col = 0; 
  70. while ( $recent_posts->have_posts() ) :  
  71. $recent_posts->the_post(); 
  72. $div_class = ''; 
  73. if ( $column > 1 && $col == 0 ) 
  74. echo '<div class="row-fluid">'; 
  75. if ($column == 2) { 
  76. $div_class = "span6"; 
  77. $col = $col + 1; 
  78. if ($col == 2) 
  79. $col = 0; 
  80. elseif ($column == 3) { 
  81. $div_class = "span4"; 
  82. $col = $col + 1; 
  83. if ($col == 3) 
  84. $col = 0; 
  85. elseif ($column == 4) { 
  86. $div_class = "span3"; 
  87. $col = $col + 1; 
  88. if ($col == 4) 
  89. $col = 0; 
  90.  
  91. if ($column > 1) 
  92. echo '<div class="' . $div_class .'">'; 
  93. get_template_part( 'content', 'summary' ); 
  94.  
  95. if ($column > 1) { 
  96. echo '</div>';  
  97. if ($col == 0) 
  98. echo '</div>'; 
  99. endwhile; 
  100.  
  101. if ( $col > 0 ) 
  102. echo '</div>'; 
  103. echo $after_widget; 
  104. // Reset the post globals as this query will have stomped on it 
  105. wp_reset_postdata(); 
  106. endif; 
  107.  
  108. // Update options 
  109. function update( $new, $old ) { 
  110. $instance = $old; 
  111. $instance['title'] = strip_tags( $new['title'] ); 
  112. $instance['number'] = (int) $new['number']; 
  113. $col = (int) $new['column']; 
  114. if ($col > 4) 
  115. $col = 4; 
  116. if ($col <1 ) 
  117. $col = 1; 
  118. $instance['column'] = $col; 
  119. $instance['posttype'] = $new['posttype'];  
  120. $instance['customquery'] = wp_kses_stripslashes( $new['customquery'] ); 
  121. $instance['category'] = (int) $new['category']; 
  122. $instance['sticky_post'] = (int) $new['sticky_post']; 
  123. $instance['random_post'] = (int) $new['random_post']; 
  124. $instance['entry_meta'] = (int) $new['entry_meta']; 
  125. $instance['category_link'] = strip_tags($new['category_link']); 
  126. $instance['display_excerpt'] = $new['display_excerpt']; 
  127. $instance['thumbnail'] = $new['thumbnail']; 
  128. $size = (int) $new['thumbnail_x']; 
  129. if ($size < 1) 
  130. $size = 64; 
  131. $instance['thumbnail_x'] = $size; 
  132. $size = (int) $new['thumbnail_y']; 
  133. if ($size < 1) 
  134. $size = 64; 
  135. $instance['thumbnail_y'] = $size; 
  136.  
  137. return $instance; 
  138.  
  139. function widget_defaults() { 
  140. return array( 
  141. 'title' => '',  
  142. 'posttype' => 'post',  
  143. 'number' => '10',  
  144. 'category' => '0',  
  145. 'sticky_post' => '0',  
  146. 'random_post' => '0',  
  147. 'column' => '1',  
  148. 'thumbnail' => '1',  
  149. 'thumbnail_x' => '64',  
  150. 'thumbnail_y' => '64',  
  151. 'display_excerpt' => 1,  
  152. 'entry_meta' => '0',  
  153. 'category_link' => '',  
  154. 'customquery' => '',  
  155. ); 
  156. // Display options 
  157. function form( $instance ) { 
  158. $instance = wp_parse_args($instance, $this->widget_defaults()); 
  159.  
  160. advantage_widget_field( $this, array ( 'field' => 'title', 'label' => __( 'Title:', 'advantage' ) ), $instance['title'] ); 
  161. advantage_widget_field( $this, array ( 'field' => 'posttype', 'type' => 'select', 'label' => __( 'Post Type:', 'advantage' ), 'options' => advantage_post_types(), 'class' => '' ), $instance['posttype'] ); 
  162. advantage_widget_field( $this, array ( 'field' => 'number', 'type' => 'number', 'label' => __( 'Number of posts to show:', 'advantage' ), 'class' => '' ), $instance['number'] ); 
  163. advantage_widget_field( $this, array ( 'field' => 'random_post', 'type' => 'checkbox', 'desc' => __( 'Random Posts', 'advantage' ), 'class' => '' ), $instance['random_post'] ); 
  164. advantage_widget_field( $this, array ( 'field' => 'column', 'type' => 'number', 'label' => __( 'No of Columns (1-4):', 'advantage' ), 'class' => '' ), $instance['column'] ); 
  165. advantage_widget_field( $this, array ( 'field' => 'category', 'type' => 'category', 'label' => __( 'Category:', 'advantage' ), 'label_all' => __( 'All Categories', 'advantage' ), 'options' => advantage_categories() ), $instance['category'] ); 
  166. advantage_widget_field( $this, array ( 'field' => 'sticky_post', 'type' => 'checkbox', 'desc' => __( 'Include sticky posts in the category', 'advantage' ), 'class' => '' ), $instance['sticky_post'] );  
  167. advantage_widget_field( $this, array ( 'field' => 'thumbnail', 'type' => 'select', 'label' => __( 'Thumbnail:', 'advantage' ), 'options' => advantage_thumbnail_array(), 'class' => '' ), $instance['thumbnail'] ); 
  168. ?> 
  169. <p><?php advantage_widget_field( $this, array ( 'field' => 'thumbnail_x', 'type' => 'number', 'label' => __( 'Custom size: ', 'advantage' ), 'class' => '', 'ptag' => false ), $instance['thumbnail_x'] ); advantage_widget_field( $this, array ( 'field' => 'thumbnail_y', 'type' => 'number', 'label' => __( ' x ', 'advantage' ), 'class' => '', 'ptag' => false ), $instance['thumbnail_y'] ); ?></p> 
  170. <?php advantage_widget_field( $this, array ( 'field' => 'display_excerpt', 'type' => 'select', 'label' => __( 'Intro Text: ', 'advantage' ),  
  171. 'options' => array ( 
  172. array( 'key' => '1',  
  173. 'name' => __( 'Excerpt', 'advantage' ) ),  
  174. array( 'key' => '2',  
  175. 'name' => __( 'Content', 'advantage' ) ),  
  176. array( 'key' => '3',  
  177. 'name' => __( 'None', 'advantage' ) ) ),  
  178. 'class' => '' ), $instance['display_excerpt'] ); 
  179. advantage_widget_field( $this, array ( 'field' => 'entry_meta', 'type' => 'checkbox', 'desc' => __( 'Display post meta', 'advantage' ), 'class' => '' ), $instance['entry_meta'] ); 
  180. advantage_widget_field( $this, array ( 'field' => 'category_link', 'label' => __( 'Single category link : ', 'advantage' ), 'class' => '' ), $instance['category_link'] ); 
  181. advantage_widget_field( $this, array ( 'field' => 'customquery', 'label' => __( 'Custom Query:', 'advantage' ) ), $instance['customquery'] );