Layers_Post_Widget

The Layers Layers Post Widget class.

Defined (1)

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

/core/widgets/modules/post.php  
  1. class Layers_Post_Widget extends Layers_Widget { 
  2.  
  3. /** 
  4. * Widget construction 
  5. */ 
  6. function __construct() { 
  7.  
  8. /** 
  9. * Widget variables 
  10. * @param string $widget_title Widget title 
  11. * @param string $widget_id Widget slug for use as an ID/classname 
  12. * @param string $post_type (optional) Post type for use in widget options 
  13. * @param string $taxonomy (optional) Taxonomy slug for use as an ID/classname 
  14. * @param array $checkboxes (optional) Array of checkbox names to be saved in this widget. Don't forget these please! 
  15. */ 
  16. $this->widget_title = __( 'Posts' , 'layerswp' ); 
  17. $this->widget_id = 'post'; 
  18. $this->post_type = 'post'; 
  19. $this->taxonomy = 'category'; 
  20. $this->checkboxes = array( 
  21. 'show_media',  
  22. 'show_titles',  
  23. 'show_excerpts',  
  24. 'show_dates',  
  25. 'show_author',  
  26. 'show_tags',  
  27. 'show_categories',  
  28. 'show_call_to_action' 
  29. ); // @TODO: Try make this more dynamic, or leave a different note reminding users to change this if they add/remove checkboxes 
  30.  
  31. /** Widget settings. */ 
  32. $widget_ops = array( 
  33. 'classname' => 'obox-layers-' . $this->widget_id .'-widget',  
  34. 'description' => __( 'This widget is used to display your posts in a flexible grid.', 'layerswp' ),  
  35. 'customize_selective_refresh' => TRUE,  
  36. ); 
  37.  
  38. /** Widget control settings. */ 
  39. $control_ops = array( 
  40. 'width' => LAYERS_WIDGET_WIDTH_SMALL,  
  41. 'height' => NULL,  
  42. 'id_base' => LAYERS_THEME_SLUG . '-widget-' . $this->widget_id,  
  43. ); 
  44.  
  45. /** Create the widget. */ 
  46. parent::__construct( 
  47. LAYERS_THEME_SLUG . '-widget-' . $this->widget_id,  
  48. $this->widget_title,  
  49. $widget_ops,  
  50. $control_ops 
  51. ); 
  52.  
  53. /** Setup Widget Defaults */ 
  54. $this->defaults = array ( 
  55. 'title' => __( 'Latest Posts', 'layerswp' ),  
  56. 'excerpt' => __( 'Stay up to date with all our latest news and launches. Only the best quality makes it onto our blog!', 'layerswp' ),  
  57. 'text_style' => 'regular',  
  58. 'category' => 0,  
  59. 'show_media' => 'on',  
  60. 'show_titles' => 'on',  
  61. 'show_excerpts' => 'on',  
  62. 'show_dates' => 'on',  
  63. 'show_author' => 'on',  
  64. 'show_tags' => 'on',  
  65. 'show_categories' => 'on',  
  66. 'show_pagination' => 'on',  
  67. 'excerpt_length' => 200,  
  68. 'show_call_to_action' => 'on',  
  69. 'call_to_action' => __( 'Read More' , 'layerswp' ),  
  70. 'posts_per_page' => get_option( 'posts_per_page' ),  
  71. 'design' => array( 
  72. 'layout' => 'layout-boxed',  
  73. 'imageratios' => 'image-square',  
  74. 'textalign' => 'text-left',  
  75. 'liststyle' => 'list-grid',  
  76. 'columns' => '3',  
  77. 'gutter' => 'on',  
  78. 'background' => array( 
  79. 'position' => 'center',  
  80. 'repeat' => 'no-repeat' 
  81. ),  
  82. 'fonts' => array( 
  83. 'align' => 'text-left',  
  84. 'size' => 'medium',  
  85. 'color' => NULL,  
  86. 'shadow' => NULL,  
  87. 'heading-type' => 'h3',  
  88. ),  
  89. 'buttons' => array( 
  90. 'buttons-size' => 'medium',  
  91. ); 
  92.  
  93. /** 
  94. * Widget front end display 
  95. */ 
  96. function widget( $args, $instance ) { 
  97. global $wp_customize; 
  98.  
  99. $this->backup_inline_css(); 
  100.  
  101. // Turn $args array into variables. 
  102. extract( $args ); 
  103.  
  104. // Use defaults if $instance is empty. 
  105. if( empty( $instance ) && ! empty( $this->defaults ) ) { 
  106. $instance = wp_parse_args( $instance, $this->defaults ); 
  107.  
  108. // Mix in new/unset defaults on every instance load (NEW) 
  109. $instance = $this->apply_defaults( $instance ); 
  110.  
  111. // Enqueue Masonry if need be 
  112. if( 'list-masonry' == $this->check_and_return( $instance , 'design', 'liststyle' ) ) { 
  113. wp_enqueue_script( LAYERS_THEME_SLUG . '-layers-masonry-js' ); 
  114.  
  115. // Set the span class for each column 
  116. if( 'list-list' == $instance['design'][ 'liststyle' ] ) { 
  117. $col_count = 1; 
  118. $span_class = 'span-12'; 
  119. } else if( isset( $instance['design'][ 'columns'] ) ) { 
  120. $col_count = str_ireplace('columns-', '', $instance['design'][ 'columns'] ); 
  121. $span_class = 'span-' . ( 12/ $col_count ); 
  122. } else { 
  123. $col_count = 3; 
  124. $span_class = 'span-4'; 
  125.  
  126. // Apply Styling 
  127. $this->inline_css .= layers_inline_styles( '#' . $widget_id, 'background', array( 'background' => $instance['design'][ 'background' ] ) ); 
  128. $this->inline_css .= layers_inline_styles( '#' . $widget_id, 'color', array( 'selectors' => array( '.section-title .heading' , '.section-title div.excerpt' ) , 'color' => $instance['design']['fonts'][ 'color' ] ) ); 
  129. $this->inline_css .= layers_inline_styles( '#' . $widget_id, 'background', array( 'selectors' => array( '.thumbnail-body' ) , 'background' => array( 'color' => $this->check_and_return( $instance, 'design', 'column-background-color' ) ) ) ); 
  130.  
  131. // Apply Button Styling. 
  132. $button_size = ''; 
  133. if ( function_exists( 'layers_pro_apply_widget_button_styling' ) ) { 
  134. // Apply Layers Pro Button Styling. 
  135. $this->inline_css .= layers_pro_apply_widget_button_styling( $this, $instance, array( "#{$widget_id} .thumbnail-body a.button" ) ); 
  136. $button_size = $this->check_and_return( $instance, 'design', 'buttons-size' ) ? 'btn-' . $this->check_and_return( $instance, 'design', 'buttons-size' ) : '' ; 
  137. else { 
  138. // Apply Button Styling. 
  139. $this->inline_css .= layers_inline_button_styles( "#{$widget_id}", 'button', array( 'selectors' => array( '.thumbnail-body a.button' ) , 'button' => $this->check_and_return( $instance, 'design', 'buttons' ) ) ); 
  140.  
  141. // Set Image Sizes 
  142. if( isset( $instance['design'][ 'imageratios' ] ) ) { 
  143.  
  144. // Translate Image Ratio 
  145. $image_ratio = layers_translate_image_ratios( $instance['design'][ 'imageratios' ] ); 
  146.  
  147. if( 'layout-boxed' == $this->check_and_return( $instance , 'design', 'layout' ) && $col_count > 2 ) { 
  148. $use_image_ratio = $image_ratio . '-medium'; 
  149. } elseif( 'layout-boxed' != $this->check_and_return( $instance , 'design', 'layout' ) && $col_count > 3 ) { 
  150. $use_image_ratio = $image_ratio . '-large'; 
  151. } else { 
  152. $use_image_ratio = $image_ratio . '-large'; 
  153. } else { 
  154. $use_image_ratio = 'large'; 
  155.  
  156. // Begin query arguments 
  157. $query_args = array(); 
  158. if( get_query_var('paged') ) { 
  159. $query_args[ 'paged' ] = get_query_var('paged') ; 
  160. } else if ( get_query_var('page') ) { 
  161. $query_args[ 'paged' ] = get_query_var('page'); 
  162. } else { 
  163. $query_args[ 'paged' ] = 1; 
  164.  
  165. $query_args[ 'post_type' ] = $this->post_type; 
  166. $query_args[ 'posts_per_page' ] = $instance['posts_per_page']; 
  167. if( isset( $instance['order'] ) ) { 
  168.  
  169. $decode_order = json_decode( $instance['order'], true ); 
  170.  
  171. if( is_array( $decode_order ) ) { 
  172. foreach( $decode_order as $key => $value ) { 
  173. $query_args[ $key ] = $value; 
  174.  
  175. // Do the special taxonomy array() 
  176. if( isset( $instance['category'] ) && '' != $instance['category'] && 0 != $instance['category'] ) { 
  177.  
  178. $query_args['tax_query'] = array( 
  179. array( 
  180. "taxonomy" => $this->taxonomy,  
  181. "field" => "id",  
  182. "terms" => $instance['category'] 
  183. ); 
  184. } elseif( !isset( $instance['hide_category_filter'] ) ) { 
  185. $terms = get_terms( $this->taxonomy ); 
  186. } // if we haven't selected which category to show, let's load the $terms for use in the filter 
  187.  
  188. // Do the WP_Query 
  189. $post_query = new WP_Query( $query_args ); 
  190.  
  191. // Set the meta to display 
  192. global $layers_post_meta_to_display; 
  193. $layers_post_meta_to_display = array(); 
  194. if( isset( $instance['show_dates'] ) ) $layers_post_meta_to_display[] = 'date'; 
  195. if( isset( $instance['show_author'] ) ) $layers_post_meta_to_display[] = 'author'; 
  196. if( isset( $instance['show_categories'] ) ) $layers_post_meta_to_display[] = 'categories'; 
  197. if( isset( $instance['show_tags'] ) ) $layers_post_meta_to_display[] = 'tags'; 
  198.  
  199. // Apply the advanced widget styling 
  200. $this->apply_widget_advanced_styling( $widget_id, $instance ); 
  201.  
  202. /** 
  203. * Generate the widget container class 
  204. */ 
  205. $widget_container_class = array(); 
  206.  
  207. $widget_container_class[] = 'widget'; 
  208. $widget_container_class[] = 'layers-post-widget'; 
  209. $widget_container_class[] = 'content-vertical-massive'; 
  210. $widget_container_class[] = 'clearfix'; 
  211. $widget_container_class[] = ( 'on' == $this->check_and_return( $instance , 'design', 'background', 'darken' ) ? 'darken' : '' ); 
  212. $widget_container_class[] = $this->check_and_return( $instance , 'design', 'advanced', 'customclass' ); // Apply custom class from design-bar's advanced control. 
  213. $widget_container_class[] = $this->get_widget_spacing_class( $instance ); 
  214.  
  215. $widget_container_class = apply_filters( 'layers_post_widget_container_class' , $widget_container_class, $this, $instance ); 
  216. $widget_container_class = implode( ' ', $widget_container_class ); 
  217.  
  218. // Custom Anchor 
  219. echo $this->custom_anchor( $instance ); ?> 
  220.  
  221. <div id="<?php echo esc_attr( $widget_id ); ?>" class="<?php echo esc_attr( $widget_container_class ); ?>" <?php $this->selective_refresh_atts( $args ); ?>> 
  222.  
  223. <?php do_action( 'layers_before_post_widget_inner', $this, $instance ); ?> 
  224.  
  225. <?php if( '' != $this->check_and_return( $instance , 'title' ) ||'' != $this->check_and_return( $instance , 'excerpt' ) ) { ?> 
  226. <div class="container clearfix"> 
  227. <?php /** 
  228. * Generate the Section Title Classes 
  229. */ 
  230. $section_title_class = array(); 
  231. $section_title_class[] = 'section-title clearfix'; 
  232. $section_title_class[] = $this->check_and_return( $instance , 'design', 'fonts', 'size' ); 
  233. $section_title_class[] = $this->check_and_return( $instance , 'design', 'fonts', 'align' ); 
  234. $section_title_class[] = ( $this->check_and_return( $instance, 'design', 'background' , 'color' ) && 'dark' == layers_is_light_or_dark( $this->check_and_return( $instance, 'design', 'background' , 'color' ) ) ? 'invert' : '' ); 
  235. $section_title_class = implode( ' ', $section_title_class ); ?> 
  236. <div class="<?php echo $section_title_class; ?>"> 
  237. <?php if( '' != $this->check_and_return( $instance, 'title' ) ) { ?> 
  238. <<?php echo $this->check_and_return( $instance, 'design', 'fonts', 'heading-type' ); ?> class="heading"> 
  239. <?php echo $instance['title'] ?> 
  240. </<?php echo $this->check_and_return( $instance, 'design', 'fonts', 'heading-type' ); ?>> 
  241. <?php } ?> 
  242. <?php if( '' != $this->check_and_return( $instance, 'excerpt' ) ) { ?> 
  243. <div class="excerpt"><?php echo layers_the_content( $instance['excerpt'] ); ?></div> 
  244. <?php } ?> 
  245. </div> 
  246. </div> 
  247. <?php } ?> 
  248. <?php if( $post_query->have_posts() ) { ?> 
  249. <div class="<?php echo $this->get_widget_layout_class( $instance ); ?> <?php echo $this->check_and_return( $instance , 'design', 'liststyle' ); ?>"> 
  250. <div class="grid"> 
  251. <?php while( $post_query->have_posts() ) { 
  252. $post_query->the_post(); 
  253.  
  254. if( 'list-list' == $instance['design'][ 'liststyle' ] ) { ?> 
  255. <article id="post-<?php the_ID(); ?>" class="clearfix push-bottom-large"> 
  256. <?php if( isset( $instance['show_titles'] ) ) { ?> 
  257. <header class="section-title large"> 
  258. <h1 class="heading"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1> 
  259. </header> 
  260. <?php } ?> 
  261.  
  262. <?php // Layers Featured Media ); 
  263. if( isset( $instance['show_media'] ) ) { 
  264. echo layers_post_featured_media( 
  265. array( 
  266. 'postid' => get_the_ID(),  
  267. 'wrap_class' => 'thumbnail push-bottom span-5 column' . ( 'image-round' == $this->check_and_return( $instance, 'design', 'imageratios' ) ? ' image-rounded' : '' ),  
  268. 'size' => $use_image_ratio 
  269. ); 
  270. } // if Show Media ?> 
  271.  
  272. <?php if( isset( $instance['show_excerpts'] ) || $instance['show_call_to_action'] || ! empty( $layers_post_meta_to_display ) ) { ?> 
  273. <div class="column span-7"> 
  274. <?php if( isset( $instance['show_excerpts'] ) ) { 
  275. if( isset( $instance['excerpt_length'] ) && '' == $instance['excerpt_length'] ) { 
  276. echo '<div class="copy push-bottom">'; 
  277. the_content(); 
  278. echo '</div>'; 
  279. } else if( isset( $instance['excerpt_length'] ) && 0 != $instance['excerpt_length'] && strlen( get_the_excerpt() ) > $instance['excerpt_length'] ) { 
  280. echo '<div class="copy push-bottom">' . substr( get_the_excerpt() , 0 , $instance['excerpt_length'] ) . '…</div>'; 
  281. } else if( '' != get_the_excerpt() ) { 
  282. echo '<div class="copy push-bottom">' . get_the_excerpt() . '</div>'; 
  283. }; ?> 
  284.  
  285. <?php layers_post_meta( get_the_ID(), $layers_post_meta_to_display, 'footer' , 'meta-info push-bottom ' . ( '' != $this->check_and_return( $instance, 'design', 'column-background-color' ) && 'dark' == layers_is_light_or_dark( $this->check_and_return( $instance, 'design', 'column-background-color' ) ) ? 'invert' : '' ) );?> 
  286.  
  287. <?php if( isset( $instance['show_call_to_action'] ) && $this->check_and_return( $instance , 'call_to_action' ) ) { ?> 
  288. <p><a href="<?php the_permalink(); ?>" class="button <?php echo $button_size; ?>"><?php echo $instance['call_to_action']; ?></a></p> 
  289. <?php } // show call to action ?> 
  290. </div> 
  291. <?php } ?> 
  292. </article> 
  293. <?php } else { 
  294. /** 
  295. * Set Individual Column CSS 
  296. */ 
  297. $post_column_class = array(); 
  298. $post_column_class[] = 'layers-masonry-column'; 
  299. $post_column_class[] = 'thumbnail'; 
  300. $post_column_class[] = ( 'list-masonry' == $this->check_and_return( $instance, 'design', 'liststyle' ) ? 'no-gutter' : '' ); 
  301. $post_column_class[] = 'column' . ( 'on' != $this->check_and_return( $instance, 'design', 'gutter' ) ? '-flush' : '' ); 
  302. $post_column_class[] = $span_class; 
  303. $post_column_class[] = ( 'overlay' == $this->check_and_return( $instance , 'text_style' ) ? 'with-overlay' : '' ) ; 
  304. $post_column_class[] = ( '' != $this->check_and_return( $instance, 'design', 'column-background-color' ) && 'dark' == layers_is_light_or_dark( $this->check_and_return( $instance, 'design', 'column-background-color' ) ) ? 'invert' : '' ); 
  305. $post_column_class = implode( ' ' , $post_column_class ); ?> 
  306.  
  307. <article class="<?php echo $post_column_class; ?>" data-cols="<?php echo $col_count; ?>"> 
  308. <?php // Layers Featured Media 
  309. if( isset( $instance['show_media'] ) ) { 
  310. echo layers_post_featured_media( 
  311. array( 
  312. 'postid' => get_the_ID(),  
  313. 'wrap_class' => 'thumbnail-media' . ( ( 'image-round' == $this->check_and_return( $instance, 'design', 'imageratios' ) ) ? ' image-rounded' : '' ),  
  314. 'size' => $use_image_ratio,  
  315. 'hide_href' => false 
  316. ); 
  317. } // if Show Media ?> 
  318. <?php if( isset( $instance['show_titles'] ) || isset( $instance['show_excerpts'] ) ) { ?> 
  319. <div class="thumbnail-body"> 
  320. <div class="overlay"> 
  321. <?php if( isset( $instance['show_titles'] ) ) { ?> 
  322. <header class="article-title"> 
  323. <h4 class="heading"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4> 
  324. </header> 
  325. <?php } ?> 
  326. <?php if( isset( $instance['show_excerpts'] ) ) { 
  327. if( isset( $instance['excerpt_length'] ) && '' == $instance['excerpt_length'] ) { 
  328. echo '<div class="excerpt">'; 
  329. the_content(); 
  330. echo '</div>'; 
  331. } else if( isset( $instance['excerpt_length'] ) && 0 != $instance['excerpt_length'] && strlen( get_the_excerpt() ) > $instance['excerpt_length'] ) { 
  332. echo '<div class="excerpt">' . substr( get_the_excerpt() , 0 , $instance['excerpt_length'] ) . '…</div>'; 
  333. } else if( '' != get_the_excerpt() ) { 
  334. echo '<div class="excerpt">' . get_the_excerpt() . '</div>'; 
  335. }; ?> 
  336. <?php if( 'overlay' != $this->check_and_return( $instance, 'text_style' ) ) { ?> 
  337. <?php layers_post_meta( get_the_ID(), $layers_post_meta_to_display, 'footer' , 'meta-info ' . ( '' != $this->check_and_return( $instance, 'design', 'column-background-color' ) && 'dark' == layers_is_light_or_dark( $this->check_and_return( $instance, 'design', 'column-background-color' ) ) ? 'invert' : '' ) );?> 
  338. <?php } // Don't show meta if we have chosen overlay ?> 
  339. <?php if( isset( $instance['show_call_to_action'] ) && $this->check_and_return( $instance , 'call_to_action' ) ) { ?> 
  340. <a href="<?php the_permalink(); ?>" class="button <?php echo $button_size; ?>"><?php echo $instance['call_to_action']; ?></a> 
  341. <?php } // show call to action ?> 
  342. </div> 
  343. </div> 
  344. <?php } // if show titles || show excerpt ?> 
  345. </article> 
  346. <?php }; // if list-list == liststyle ?> 
  347. <?php }; // while have_posts ?> 
  348. </div><!-- /row --> 
  349. </div> 
  350. <?php }; // if have_posts ?> 
  351. <?php if( isset( $instance['show_pagination'] ) ) { ?> 
  352. <div class="container"> 
  353. <?php layers_pagination( array( 'query' => $post_query ), 'div', 'pagination clearfix' ); ?> 
  354. </div> 
  355. <?php } ?> 
  356.  
  357. <?php do_action( 'layers_after_post_widget_inner', $this, $instance ); 
  358.  
  359. // Print the Inline Styles for this Widget 
  360. $this->print_inline_css(); 
  361.  
  362. if( 'list-masonry' == $this->check_and_return( $instance , 'design', 'liststyle' ) ) { ?> 
  363. <script type='text/javascript'> 
  364. jQuery(function($) { 
  365. $('#<?php echo $widget_id; ?>').find('.list-masonry .grid').layers_masonry({ 
  366. itemSelector: '.layers-masonry-column',  
  367. gutter: <?php echo ( isset( $instance['design'][ 'gutter' ] ) ? 20 : 0 ); ?>,  
  368. }); 
  369. }); 
  370. </script> 
  371. <?php } // masonry trigger ?> 
  372.  
  373. </div> 
  374.  
  375. <?php // Reset WP_Query 
  376. wp_reset_postdata(); 
  377.  
  378.  
  379. /** 
  380. * Widget update 
  381. */ 
  382.  
  383. function update($new_instance, $old_instance) { 
  384.  
  385. if ( isset( $this->checkboxes ) ) { 
  386. foreach( $this->checkboxes as $cb ) { 
  387. if( isset( $old_instance[ $cb ] ) ) { 
  388. $old_instance[ $cb ] = strip_tags( $new_instance[ $cb ] ); 
  389. } // foreach checkboxes 
  390. } // if checkboxes 
  391. return $new_instance; 
  392.  
  393. /** 
  394. * Widget form 
  395. * We use regulage HTML here, it makes reading the widget much easier than if we used just php to echo all the HTML out. 
  396. */ 
  397. function form( $instance ) { 
  398.  
  399. // Use defaults if $instance is empty. 
  400. if( empty( $instance ) && ! empty( $this->defaults ) ) { 
  401. $instance = wp_parse_args( $instance, $this->defaults ); 
  402.  
  403. // Mix in new/unset defaults on every instance load (NEW) 
  404. $instance = $this->apply_defaults( $instance ); 
  405.  
  406. $this->design_bar( 
  407. 'side', // CSS Class Name 
  408. array( // Widget Object 
  409. 'name' => $this->get_layers_field_name( 'design' ),  
  410. 'id' => $this->get_layers_field_id( 'design' ),  
  411. 'widget_id' => $this->widget_id,  
  412. ),  
  413. $instance, // Widget Values 
  414. apply_filters( 'layers_post_widget_design_bar_components' , array( // Components 
  415. 'layout',  
  416. 'display' => array( 
  417. 'icon-css' => 'icon-display',  
  418. 'label' => __( 'Display', 'layerswp' ),  
  419. 'elements' => array( 
  420. 'text_style' => array( 
  421. 'type' => 'select',  
  422. 'name' => $this->get_layers_field_name( 'text_style' ) ,  
  423. 'id' => $this->get_layers_field_id( 'text_style' ) ,  
  424. 'value' => ( isset( $instance['text_style'] ) ) ? $instance['text_style'] : NULL,  
  425. 'label' => __( 'Title & Excerpt Position' , 'layerswp' ),  
  426. 'options' => array( 
  427. 'regular' => __( 'Regular' , 'layerswp' ),  
  428. 'overlay' => __( 'Overlay' , 'layerswp' ) 
  429. ),  
  430. 'show_pagination' => array( 
  431. 'type' => 'checkbox',  
  432. 'name' => $this->get_layers_field_name( 'show_pagination' ) ,  
  433. 'id' => $this->get_layers_field_id( 'show_pagination' ) ,  
  434. 'value' => ( isset( $instance['show_pagination'] ) ) ? $instance['show_pagination'] : NULL,  
  435. 'label' => __( 'Show Pagination' , 'layerswp' ) 
  436. ),  
  437. 'show_media' => array( 
  438. 'type' => 'checkbox',  
  439. 'name' => $this->get_layers_field_name( 'show_media' ) ,  
  440. 'id' => $this->get_layers_field_id( 'show_media' ) ,  
  441. 'value' => ( isset( $instance['show_media'] ) ) ? $instance['show_media'] : NULL,  
  442. 'label' => __( 'Show Featured Images' , 'layerswp' ) 
  443. ),  
  444. 'show_titles' => array( 
  445. 'type' => 'checkbox',  
  446. 'name' => $this->get_layers_field_name( 'show_titles' ) ,  
  447. 'id' => $this->get_layers_field_id( 'show_titles' ) ,  
  448. 'value' => ( isset( $instance['show_titles'] ) ) ? $instance['show_titles'] : NULL,  
  449. 'label' => __( 'Show Post Titles' , 'layerswp' ) 
  450. ),  
  451. 'show_excerpts' => array( 
  452. 'type' => 'checkbox',  
  453. 'name' => $this->get_layers_field_name( 'show_excerpts' ) ,  
  454. 'id' => $this->get_layers_field_id( 'show_excerpts' ) ,  
  455. 'value' => ( isset( $instance['show_excerpts'] ) ) ? $instance['show_excerpts'] : NULL,  
  456. 'label' => __( 'Show Post Excerpts' , 'layerswp' ),  
  457. 'data' => array( 
  458. 'show-if-selector' => '#' . $this->get_layers_field_id( 'text_style' ),  
  459. 'show-if-value' => 'overlay',  
  460. 'show-if-operator' => '!=' 
  461. ),  
  462. ),  
  463. 'excerpt_length' => array( 
  464. 'type' => 'number',  
  465. 'name' => $this->get_layers_field_name( 'excerpt_length' ) ,  
  466. 'id' => $this->get_layers_field_id( 'excerpt_length' ) ,  
  467. 'min' => 0,  
  468. 'max' => 10000,  
  469. 'value' => ( isset( $instance['excerpt_length'] ) ) ? $instance['excerpt_length'] : NULL,  
  470. 'label' => __( 'Excerpts Length' , 'layerswp' ),  
  471. 'data' => array( 'show-if-selector' => '#' . $this->get_layers_field_id( 'show_excerpts' ), 'show-if-value' => 'true' ),  
  472. ),  
  473. 'show_dates' => array( 
  474. 'type' => 'checkbox',  
  475. 'name' => $this->get_layers_field_name( 'show_dates' ) ,  
  476. 'id' => $this->get_layers_field_id( 'show_dates' ) ,  
  477. 'value' => ( isset( $instance['show_dates'] ) ) ? $instance['show_dates'] : NULL,  
  478. 'label' => __( 'Show Post Dates' , 'layerswp' ),  
  479. 'data' => array( 
  480. 'show-if-selector' => '#' . $this->get_layers_field_id( 'text_style' ),  
  481. 'show-if-value' => 'overlay',  
  482. 'show-if-operator' => '!=' 
  483. ),  
  484. ),  
  485. 'show_author' => array( 
  486. 'type' => 'checkbox',  
  487. 'name' => $this->get_layers_field_name( 'show_author' ) ,  
  488. 'id' => $this->get_layers_field_id( 'show_author' ) ,  
  489. 'value' => ( isset( $instance['show_author'] ) ) ? $instance['show_author'] : NULL,  
  490. 'label' => __( 'Show Post Author' , 'layerswp' ),  
  491. 'data' => array( 
  492. 'show-if-selector' => '#' . $this->get_layers_field_id( 'text_style' ),  
  493. 'show-if-value' => 'overlay',  
  494. 'show-if-operator' => '!=' 
  495. ),  
  496. ),  
  497. 'show_tags' => array( 
  498. 'type' => 'checkbox',  
  499. 'name' => $this->get_layers_field_name( 'show_tags' ) ,  
  500. 'id' => $this->get_layers_field_id( 'show_tags' ) ,  
  501. 'value' => ( isset( $instance['show_tags'] ) ) ? $instance['show_tags'] : NULL,  
  502. 'label' => __( 'Show Tags' , 'layerswp' ),  
  503. 'data' => array( 
  504. 'show-if-selector' => '#' . $this->get_layers_field_id( 'text_style' ),  
  505. 'show-if-value' => 'overlay',  
  506. 'show-if-operator' => '!=' 
  507. ),  
  508. ),  
  509. 'show_categories' => array( 
  510. 'type' => 'checkbox',  
  511. 'name' => $this->get_layers_field_name( 'show_categories' ) ,  
  512. 'id' => $this->get_layers_field_id( 'show_categories' ) ,  
  513. 'value' => ( isset( $instance['show_categories'] ) ) ? $instance['show_categories'] : NULL,  
  514. 'label' => __( 'Show Categories' , 'layerswp' ),  
  515. 'data' => array( 
  516. 'show-if-selector' => '#' . $this->get_layers_field_id( 'text_style' ),  
  517. 'show-if-value' => 'overlay',  
  518. 'show-if-operator' => '!=' 
  519. ),  
  520. ),  
  521. 'show_call_to_action' => array( 
  522. 'type' => 'checkbox',  
  523. 'name' => $this->get_layers_field_name( 'show_call_to_action' ) ,  
  524. 'id' => $this->get_layers_field_id( 'show_call_to_action' ) ,  
  525. 'value' => ( isset( $instance['show_call_to_action'] ) ) ? $instance['show_call_to_action'] : NULL,  
  526. 'label' => __( 'Show "Read More" Buttons' , 'layerswp' ),  
  527. ),  
  528. 'call_to_action' => array( 
  529. 'type' => 'text',  
  530. 'name' => $this->get_layers_field_name( 'call_to_action' ) ,  
  531. 'id' => $this->get_layers_field_id( 'call_to_action' ) ,  
  532. 'value' => ( isset( $instance['call_to_action'] ) ) ? $instance['call_to_action'] : NULL,  
  533. 'label' => __( '"Read More" Text' , 'layerswp' ),  
  534. 'data' => array( 'show-if-selector' => '#' . $this->get_layers_field_id( 'show_call_to_action' ), 'show-if-value' => 'true' ),  
  535. ),  
  536. ),  
  537. ),  
  538. 'columns',  
  539. 'buttons',  
  540. 'liststyle',  
  541. 'imageratios',  
  542. 'background',  
  543. 'advanced',  
  544. ), $this, $instance ) 
  545. ); ?> 
  546. <div class="layers-container-large"> 
  547.  
  548. <?php $this->form_elements()->header( array( 
  549. 'title' => __( 'Post' , 'layerswp' ),  
  550. 'icon_class' =>'post' 
  551. ) ); ?> 
  552.  
  553. <section class="layers-accordion-section layers-content"> 
  554.  
  555. <div class="layers-row layers-push-bottom"> 
  556. <div class="layers-form-item"> 
  557.  
  558. <?php echo $this->form_elements()->input( 
  559. array( 
  560. 'type' => 'text',  
  561. 'name' => $this->get_layers_field_name( 'title' ) ,  
  562. 'id' => $this->get_layers_field_id( 'title' ) ,  
  563. 'placeholder' => __( 'Enter title here' , 'layerswp' ),  
  564. 'value' => ( isset( $instance['title'] ) ) ? $instance['title'] : NULL,  
  565. 'class' => 'layers-text layers-large' 
  566. ); ?> 
  567.  
  568. <?php $this->design_bar( 
  569. 'top', // CSS Class Name 
  570. array( // Widget Object 
  571. 'name' => $this->get_layers_field_name( 'design' ),  
  572. 'id' => $this->get_layers_field_id( 'design' ),  
  573. 'widget_id' => $this->widget_id,  
  574. 'show_trash' => FALSE,  
  575. 'inline' => TRUE,  
  576. 'align' => 'right',  
  577. ),  
  578. $instance, // Widget Values 
  579. apply_filters( 'layers_post_widget_inline_design_bar_components', array( // Components 
  580. 'fonts',  
  581. ), $this, $instance ) 
  582. ); ?> 
  583.  
  584. </div> 
  585. <div class="layers-form-item"> 
  586.  
  587. <?php echo $this->form_elements()->input( 
  588. array( 
  589. 'type' => 'rte',  
  590. 'name' => $this->get_layers_field_name( 'excerpt' ) ,  
  591. 'id' => $this->get_layers_field_id( 'excerpt' ) ,  
  592. 'placeholder' => __( 'Short Excerpt' , 'layerswp' ),  
  593. 'value' => ( isset( $instance['excerpt'] ) ) ? $instance['excerpt'] : NULL,  
  594. 'class' => 'layers-textarea layers-large' 
  595. ); ?> 
  596.  
  597. </div> 
  598. <?php // Grab the terms as an array and loop 'em to generate the $options for the input 
  599. $terms = get_terms( $this->taxonomy , array( 'hide_empty' => false ) ); 
  600. if( !is_wp_error( $terms ) ) { ?> 
  601. <p class="layers-form-item"> 
  602. <label for="<?php echo $this->get_layers_field_id( 'category' ); ?>"><?php echo __( 'Category to Display' , 'layerswp' ); ?></label> 
  603. <?php $category_options[ 0 ] = __( 'All' , 'layerswp' ); 
  604. foreach ( $terms as $t ) $category_options[ $t->term_id ] = $t->name; 
  605. echo $this->form_elements()->input( 
  606. array( 
  607. 'type' => 'select',  
  608. 'name' => $this->get_layers_field_name( 'category' ) ,  
  609. 'id' => $this->get_layers_field_id( 'category' ) ,  
  610. 'placeholder' => __( 'Select a Category' , 'layerswp' ),  
  611. 'value' => ( isset( $instance['category'] ) ) ? $instance['category'] : NULL,  
  612. 'options' => $category_options,  
  613. ); ?> 
  614. </p> 
  615. <?php } // if !is_wp_error ?> 
  616. <p class="layers-form-item"> 
  617. <label for="<?php echo $this->get_layers_field_id( 'posts_per_page' ); ?>"><?php echo __( 'Number of items to show' , 'layerswp' ); ?></label> 
  618. <?php $select_options[ '-1' ] = __( 'Show All' , 'layerswp' ); 
  619. $select_options = $this->form_elements()->get_incremental_options( $select_options , 1 , 20 , 1); 
  620. echo $this->form_elements()->input( 
  621. array( 
  622. 'type' => 'number',  
  623. 'name' => $this->get_layers_field_name( 'posts_per_page' ) ,  
  624. 'id' => $this->get_layers_field_id( 'posts_per_page' ) ,  
  625. 'value' => ( isset( $instance['posts_per_page'] ) ) ? $instance['posts_per_page'] : NULL,  
  626. 'min' => '-1',  
  627. 'max' => '100' 
  628. ); ?> 
  629. </p> 
  630.  
  631. <p class="layers-form-item"> 
  632. <label for="<?php echo $this->get_layers_field_id( 'order' ); ?>"><?php echo __( 'Sort by' , 'layerswp' ); ?></label> 
  633. <?php echo $this->form_elements()->input( 
  634. array( 
  635. 'type' => 'select',  
  636. 'name' => $this->get_layers_field_name( 'order' ) ,  
  637. 'id' => $this->get_layers_field_id( 'order' ) ,  
  638. 'value' => ( isset( $instance['order'] ) ) ? $instance['order'] : NULL,  
  639. 'options' => $this->form_elements()->get_sort_options() 
  640. ); ?> 
  641. </p> 
  642. </div> 
  643. </section> 
  644.  
  645. </div> 
  646. <?php } // Form 
  647. } // Class