Guest User

Untitled

a guest
Dec 21st, 2018
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.43 KB | None | 0 0
  1. if (!class_exists('avia_newsbox'))
  2. {
  3. class avia_newsbox extends WP_Widget {
  4.  
  5. var $avia_term = '';
  6. var $avia_post_type = '';
  7. var $avia_new_query = '';
  8.  
  9. function __construct()
  10. {
  11. $widget_ops = array('classname' => 'newsbox', 'description' => __('A Sidebar widget to display latest post entries in your sidebar', 'avia_framework') );
  12.  
  13. parent::__construct( 'newsbox', THEMENAME.' Latest News', $widget_ops );
  14. }
  15.  
  16. function widget($args, $instance)
  17. {
  18. global $avia_config;
  19.  
  20. extract($args, EXTR_SKIP);
  21. echo $before_widget;
  22.  
  23. $title = empty($instance['title']) ? '' : apply_filters('widget_title', $instance['title']);
  24. $count = empty($instance['count']) ? '' : $instance['count'];
  25. $cat = empty($instance['cat']) ? '' : $instance['cat'];
  26. $excerpt = empty($instance['excerpt']) ? '' : $instance['excerpt'];
  27. $image_size = isset($avia_config['widget_image_size']) ? $avia_config['widget_image_size'] : 'widget';
  28.  
  29. if ( !empty( $title ) ) { echo $before_title . $title . $after_title; };
  30.  
  31.  
  32. if(empty($this->avia_term))
  33. {
  34. $additional_loop = new WP_Query("cat=".$cat."&posts_per_page=".$count);
  35. }
  36. else
  37. {
  38. $catarray = explode(',', $cat);
  39.  
  40.  
  41. if(empty($catarray[0]))
  42. {
  43. $new_query = array("posts_per_page"=>$count,"post_type"=>$this->avia_post_type);
  44. }
  45. else
  46. {
  47. if($this->avia_new_query)
  48. {
  49. $new_query = $this->avia_new_query;
  50. }
  51. else
  52. {
  53. $new_query = array( "posts_per_page"=>$count, 'tax_query' => array(
  54. array( 'taxonomy' => $this->avia_term,
  55. 'field' => 'id',
  56. 'terms' => explode(',', $cat),
  57. 'operator' => 'IN')
  58. )
  59. );
  60. }
  61. }
  62.  
  63. $additional_loop = new WP_Query($new_query);
  64. }
  65.  
  66. if($additional_loop->have_posts()) :
  67.  
  68.  
  69.  
  70. echo '<ul class="news-wrap image_size_'.$image_size.'">';
  71. while ($additional_loop->have_posts()) : $additional_loop->the_post();
  72.  
  73. $format = "";
  74. if(empty($this->avia_post_type)) $format = $this->avia_post_type;
  75. if(empty($format)) $format = get_post_format();
  76. if(empty($format)) $format = 'standard';
  77.  
  78. $the_id = get_the_ID();
  79. $link = get_post_meta( $the_id ,'_portfolio_custom_link', true) != "" ? get_post_meta( $the_id ,'_portfolio_custom_link_url', true) : get_permalink();
  80.  
  81.  
  82. echo '<li class="news-content post-format-'.$format.'">';
  83.  
  84. //check for preview images:
  85. $image = "";
  86.  
  87. if(!current_theme_supports('force-post-thumbnails-in-widget'))
  88. {
  89. $slides = avia_post_meta(get_the_ID(), 'slideshow', true);
  90.  
  91. if( $slides != "" && !empty( $slides[0]['slideshow_image'] ) )
  92. {
  93. $image = avia_image_by_id($slides[0]['slideshow_image'], $image_size, 'image');
  94. }
  95. }
  96.  
  97. if(current_theme_supports( 'post-thumbnails' ) && !$image )
  98. {
  99. $image = get_the_post_thumbnail( $the_id, $image_size );
  100. }
  101.  
  102. $time_format = apply_filters( 'avia_widget_time', get_option('date_format')." - ".get_option('time_format'), 'avia_newsbox' );
  103.  
  104.  
  105. echo "<a class='news-link' title='".get_the_title()."' href='".$link."'>";
  106.  
  107. $nothumb = (!$image) ? 'no-news-thumb' : '';
  108.  
  109. echo "<span class='news-thumb $nothumb'>";
  110. echo $image;
  111. echo "</span>";
  112. if(empty($avia_config['widget_image_size']) || 'display title and excerpt' != $excerpt)
  113. {
  114. echo "<strong class='news-headline'>".get_the_title();
  115.  
  116. if($time_format)
  117. {
  118. echo "<span class='news-time'>".get_the_time($time_format)."</span>";
  119. }
  120.  
  121. echo "</strong>";
  122. }
  123. echo "</a>";
  124.  
  125. if( 'display title and excerpt' == $excerpt )
  126. {
  127. echo "<div class='news-excerpt'>";
  128.  
  129. if(!empty($avia_config['widget_image_size']))
  130. {
  131. echo "<a class='news-link-inner' title='".get_the_title()."' href='".$link."'>";
  132. echo "<strong class='news-headline'>".get_the_title()."</strong>";
  133. echo "</a>";
  134. if($time_format)
  135. {
  136. echo "<span class='news-time'>".get_the_time($time_format)."</span>";
  137. }
  138.  
  139. }
  140. the_excerpt();
  141. echo "</div>";
  142. }
  143.  
  144. echo '</li>';
  145.  
  146.  
  147. endwhile;
  148. echo "</ul>";
  149. wp_reset_postdata();
  150. endif;
  151.  
  152.  
  153. echo $after_widget;
  154.  
  155. }
  156.  
  157.  
  158. function update($new_instance, $old_instance)
  159. {
  160. $instance = $old_instance;
  161. $instance['title'] = strip_tags($new_instance['title']);
  162. $instance['count'] = strip_tags($new_instance['count']);
  163. $instance['excerpt'] = strip_tags($new_instance['excerpt']);
  164. $instance['cat'] = implode(',',$new_instance['cat']);
  165. return $instance;
  166. }
  167.  
  168.  
  169.  
  170. function form($instance)
  171. {
  172. $instance = wp_parse_args( (array) $instance, array( 'title' => '', 'count' => '', 'cat' => '', 'excerpt'=>'' ) );
  173. $title = strip_tags($instance['title']);
  174. $count = strip_tags($instance['count']);
  175. $excerpt = strip_tags($instance['excerpt']);
  176.  
  177.  
  178. $elementCat = array("name" => __("Which categories should be used for the portfolio?", 'avia_framework'),
  179. "desc" => __("You can select multiple categories here", 'avia_framework'),
  180. "id" => $this->get_field_name('cat')."[]",
  181. "type" => "select",
  182. "std" => strip_tags($instance['cat']),
  183. "class" => "",
  184. "multiple"=>6,
  185. "subtype" => "cat");
  186. //check if a different taxonomy than the default is set
  187. if(!empty($this->avia_term))
  188. {
  189. $elementCat['taxonomy'] = $this->avia_term;
  190. }
  191.  
  192.  
  193.  
  194.  
  195. $html = new avia_htmlhelper();
  196.  
  197. ?>
  198. <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:', 'avia_framework'); ?>
  199. <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" /></label></p>
  200.  
  201. <p>
  202. <label for="<?php echo $this->get_field_id('count'); ?>"><?php _e('How many entries do you want to display: ', 'avia_framework'); ?></label>
  203. <select class="widefat" id="<?php echo $this->get_field_id('count'); ?>" name="<?php echo $this->get_field_name('count'); ?>">
  204. <?php
  205. $list = "";
  206. for ($i = 1; $i <= 20; $i++ )
  207. {
  208. $selected = "";
  209. if($count == $i) $selected = 'selected="selected"';
  210.  
  211. $list .= "<option $selected value='$i'>$i</option>";
  212. }
  213. $list .= "</select>";
  214. echo $list;
  215. ?>
  216.  
  217.  
  218. </p>
  219.  
  220. <p><label for="<?php echo $this->get_field_id('cat'); ?>"><?php _e('Choose the categories you want to display (multiple selection possible):', 'avia_framework'); ?>
  221. <?php echo $html->select($elementCat); ?>
  222. </label></p>
  223.  
  224. <p>
  225. <label for="<?php echo $this->get_field_id('excerpt'); ?>"><?php _e('Display title only or title &amp; excerpt', 'avia_framework'); ?></label>
  226. <select class="widefat" id="<?php echo $this->get_field_id('excerpt'); ?>" name="<?php echo $this->get_field_name('excerpt'); ?>">
  227. <?php
  228. $list = "";
  229. $answers = array(
  230. 'show title only' => __( 'show title only', 'avia_framework' ),
  231. 'display title and excerpt' => __('display title and excerpt', 'avia_framework')
  232. );
  233.  
  234. foreach ( $answers as $key => $answer )
  235. {
  236. $selected = "";
  237. if( $key == $excerpt ) $selected = 'selected="selected"';
  238.  
  239. $list .= "<option $selected value='$key'>$answer</option>";
  240. }
  241. $list .= "</select>";
  242. echo $list;
  243. ?>
  244.  
  245.  
  246. </p>
  247.  
  248.  
  249. <?php
  250. }
  251. }
  252. }
Advertisement
Add Comment
Please, Sign In to add comment