advantage_Navigation

The Advantage advantage Navigation class.

Defined (1)

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

/inc/widgets.php  
  1. class advantage_Navigation extends WP_Widget { 
  2. function __construct() { 
  3. WP_Widget::__construct( 
  4. 'widget_advantage_navigation',  
  5. __( '(Advantage) Navigation Tabs', 'advantage' ),  
  6. array( 
  7. 'classname' => 'tab_navigation',  
  8. 'description' => __( 'Tabbed navigation.', '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. $id = substr($widget_id, 25); 
  17.  
  18. $tabs = array(); 
  19. if ($category) 
  20. $tabs[] = array( 'order' => $category,  
  21. 'type' => 'category',  
  22. 'name' => $category_label ); 
  23. if ($archive) 
  24. $tabs[] = array( 'order' => $archive,  
  25. 'type' => 'archive',  
  26. 'name' => $archive_label ); 
  27. if ($recent) 
  28. $tabs[] = array( 'order' => $recent,  
  29. 'type' => 'recent',  
  30. 'name' => $recent_label ); 
  31. if ($tag) 
  32. $tabs[] = array( 'order' => $tag,  
  33. 'type' => 'tag',  
  34. 'name' => $tag_label ); 
  35. if ($menu && $menu_id) 
  36. $tabs[] = array( 'order' => $menu,  
  37. 'type' => 'menu',  
  38. 'name' => $menu_label ); 
  39. if ( $text && ! empty( $textcontent ) ) 
  40. $tabs[] = array( 'order' => $text,  
  41. 'type' => 'text',  
  42. 'name' => $text_label ); 
  43.  
  44. advantage_sort_array($tabs, "order"); 
  45.  
  46. echo $before_widget;  
  47. if ( ! empty( $title ) ) { 
  48. echo $before_title; 
  49. echo $title; 
  50. echo $after_title; 
  51.  
  52. echo '<ul id="vntTab" class="nav nav-tabs">'; 
  53. $active = ' class="active"'; 
  54. foreach ($tabs as $tab) { 
  55. if ($tab['order'] > 0) { 
  56. echo '<li' . $active . '><a href="#'; 
  57. echo $tab['type'] . $id .'" data-toggle="tab">'; 
  58. echo $tab['name'] . '</a></li>'; 
  59. $active = ''; 
  60. }  
  61. echo '</ul>'; 
  62. echo '<div id="vntTabContent" class="tab-content">'; 
  63. $active = " in active"; 
  64. foreach ($tabs as $tab) { 
  65. if ($tab['order'] > 0) { 
  66. switch ($tab['type']) { 
  67. case 'category': 
  68. echo '<div class="widget_categories tab-pane fade' . $active; 
  69. echo '" id="' . $tab['type'] . $id . '">'; 
  70. echo '<ul>'; 
  71.  
  72. $cat_args = array(); 
  73. $cat_args['show_count'] = $showcount; 
  74. $cat_args['title_li'] = ''; 
  75. $cat_args['exclude'] = 1; 
  76. wp_list_categories( $cat_args );  
  77.  
  78. echo '</ul></div>';  
  79. break; 
  80. case 'archive': 
  81. echo '<div class="widget_archive tab-pane fade' . $active; 
  82. echo '" id="' . $tab['type'] . $id . '">'; 
  83. echo '<ul>'; 
  84.  
  85. $arc_args = array(); 
  86. $arc_args['type'] = 'monthly'; 
  87. $arc_args['show_post_count'] = $showcount;  
  88. $arc_args['limit'] = $limits; 
  89. wp_get_archives( $arc_args );  
  90.  
  91. echo '</ul></div>';  
  92. break; 
  93. case 'recent': 
  94. echo '<div class="widget_recent_entries tab-pane fade' . $active; 
  95. echo '" id="' . $tab['type'] . $id . '">'; 
  96. echo '<ul>'; 
  97.  
  98. $rec_args = array(); 
  99. $rec_args['numberposts'] = $limits; 
  100. $rec_args['post_status'] = 'publish'; 
  101. $recent_posts = wp_get_recent_posts( $rec_args );  
  102. foreach( $recent_posts as $recent_post ) { 
  103. echo '<li><a href="' . get_permalink($recent_post["ID"]) . '" title="Look '.esc_attr($recent_post["post_title"]).'" >' . $recent_post["post_title"].'</a> </li> '; 
  104. }  
  105. echo '</ul></div>';  
  106. break; 
  107. case 'tag': 
  108. echo '<div class="widget_tag_cloud tab-pane fade' . $active; 
  109. echo '" id="' . $tab['type'] . $id . '">'; 
  110. echo '<ul>'; 
  111.  
  112. $tag_args = array(); 
  113. wp_tag_cloud( $tag_args );  
  114. echo '</ul></div>';  
  115. break; 
  116. case 'menu': 
  117. echo '<div class="widget_nav_menu tab-pane fade' . $active; 
  118. echo '" id="' . $tab['type'] . $id . '">'; 
  119.  
  120. $menu_args = array(); 
  121. $menu_args['menu'] = $menu_id; 
  122. wp_nav_menu( $menu_args);  
  123. echo '</div>';  
  124. break; 
  125. case 'text': 
  126. echo '<div class="widget_nav_text tab-pane fade' . $active; 
  127. echo '" id="' . $tab['type'] . $id . '">'; 
  128. echo do_shortcode( $textcontent );  
  129. echo '</div>';  
  130. break; 
  131. $active = ''; 
  132. }  
  133. echo '</div>'; 
  134.  
  135. echo $after_widget; 
  136. // Reset the post globals as this query will have stomped on it 
  137. wp_reset_postdata(); 
  138.  
  139. // Update options 
  140. function update( $new, $old ) { 
  141. $instance = $old; 
  142. $instance['title'] = strip_tags( $new['title'] ); 
  143. $instance['category'] = (int) $new['category']; 
  144. $instance['archive'] = (int) $new['archive']; 
  145. $instance['recent'] = (int) $new['recent']; 
  146. $instance['tag'] = (int) $new['tag']; 
  147. $instance['menu'] = (int) $new['menu'];  
  148. $instance['text'] = (int) $new['text'];  
  149. $instance['showcount'] = (int) $new['showcount']; 
  150. $instance['limits'] = (int) $new['limits'];  
  151.  
  152. $instance['category_label'] = wp_kses_stripslashes($new['category_label']); 
  153. $instance['archive_label'] = wp_kses_stripslashes($new['archive_label']); 
  154. $instance['recent_label'] = wp_kses_stripslashes($new['recent_label']); 
  155. $instance['tag_label'] = wp_kses_stripslashes($new['tag_label']); 
  156. $instance['menu_label'] = wp_kses_stripslashes($new['menu_label']); 
  157. $instance['menu_id'] = $new['menu_id']; 
  158. $instance['text_label'] = wp_kses_stripslashes($new['text_label']); 
  159. $instance['textcontent'] = wp_kses_stripslashes($new['textcontent']); 
  160. $instance['data'] = $new['data']; 
  161. $items = array(); 
  162. parse_str($instance['data'], $items); 
  163.  
  164. if ( ! empty( $items['tab'] ) ) { 
  165. $ii = 1; 
  166. foreach( $items['tab'] as $item ) { 
  167. if ( $instance[ $item ] ) { 
  168. $instance[ $item ] = $ii; 
  169. $ii = $ii + 1; 
  170. }  
  171. return $instance; 
  172.  
  173. function widget_defaults() { 
  174. return array( 
  175. 'title' => '',  
  176. 'category' => '1',  
  177. 'category_label' => __('Categories', 'advantage'),  
  178. 'archive' => '2',  
  179. 'archive_label' => __('Archives', 'advantage'),  
  180. 'recent' => '0',  
  181. 'recent_label' => __('Latest', 'advantage'),  
  182. 'tag' => '3',  
  183. 'tag_label' => __('Tags', 'advantage'),  
  184. 'menu' => '0',  
  185. 'menu_label' => __('Menu', 'advantage'),  
  186. 'menu_id' => '0',  
  187. 'text' => '0',  
  188. 'text_label' => __('Text', 'advantage'),  
  189. 'showcount' => '1',  
  190. 'limits' => '10',  
  191. 'textcontent' => '',  
  192. 'data' => '',  
  193. ); 
  194.  
  195. // Display options 
  196. function form( $instance ) { 
  197. $instance = wp_parse_args( $instance, $this->widget_defaults() ); 
  198.  
  199. $tabs = array( 
  200. array( 'order' => $instance['category'],  
  201. 'type' => 'category' ),  
  202. array( 'order' => $instance['archive'],  
  203. 'type' => 'archive' ),  
  204. array( 'order' => $instance['recent'],  
  205. 'type' => 'recent' ),  
  206. array( 'order' => $instance['tag'],  
  207. 'type' => 'tag' ),  
  208. array( 'order' => $instance['menu'],  
  209. 'type' => 'menu' ),  
  210. array( 'order' => $instance['text'],  
  211. 'type' => 'text' ),  
  212. ); 
  213. advantage_sort_array($tabs, "order"); 
  214.  
  215. advantage_widget_field( $this, array ( 'field' => 'title', 'label' => __( 'Title:', 'advantage' ) ), $instance['title'] ); 
  216. ?> 
  217. <ul id="widget-nav-tabs" class="widget-sortable"> 
  218. <?php 
  219. $data = ""; 
  220. foreach( $tabs as $tab ) { 
  221. $data .= 'tab[]=' . $tab['type'] . '&'; 
  222. switch ( $tab['type'] ) { 
  223. case 'category': 
  224. if ( $instance['category'] > 0 ) 
  225. $flag = 1; 
  226. else 
  227. $flag = 0;  
  228. echo '<li id="tab_category" '; 
  229. if ( $flag ) 
  230. echo 'class="tab-selected"'; 
  231. echo '>';  
  232. advantage_widget_field( $this, array ( 'field' => 'category', 'type' => 'checkbox', 'desc' => __( 'Category', 'advantage' ), 'ptag' => false, 'class' => 'widget-checkbox' ), $flag ); 
  233. advantage_widget_field( $this, array ( 'field' => 'category_label', 'type' => 'text', 'ptag' => false, 'class' => '' ), $instance['category_label'] ); 
  234. echo '</li>'; 
  235. break; 
  236. case 'archive': 
  237. if ( $instance['archive'] > 0 ) 
  238. $flag = 1; 
  239. else 
  240. $flag = 0;  
  241. echo '<li id="tab_archive" '; 
  242. if ( $flag ) 
  243. echo 'class="tab-selected"'; 
  244. echo '>'; 
  245. advantage_widget_field( $this, array ( 'field' => 'archive', 'type' => 'checkbox', 'desc' => __( 'Archive', 'advantage' ), 'ptag' => false, 'class' => 'widget-checkbox' ), $flag ); 
  246. advantage_widget_field( $this, array ( 'field' => 'archive_label', 'type' => 'text', 'ptag' => false, 'class' => '' ), $instance['archive_label'] ); 
  247. echo '</li>'; 
  248. break; 
  249. case 'recent': 
  250. if ( $instance['recent'] > 0 ) 
  251. $flag = 1; 
  252. else 
  253. $flag = 0;  
  254. echo '<li id="tab_recent" '; 
  255. if ( $flag ) 
  256. echo 'class="tab-selected"'; 
  257. echo '>'; 
  258. advantage_widget_field( $this, array ( 'field' => 'recent', 'type' => 'checkbox', 'desc' => __( 'Recent', 'advantage' ), 'ptag' => false, 'class' => 'widget-checkbox' ), $flag ); 
  259. advantage_widget_field( $this, array ( 'field' => 'recent_label', 'type' => 'text', 'ptag' => false, 'class' => '' ), $instance['recent_label'] ); 
  260. echo '</li>'; 
  261. break; 
  262. case 'tag': 
  263. if ( $instance['tag'] > 0 ) 
  264. $flag = 1; 
  265. else 
  266. $flag = 0;  
  267. echo '<li id="tab_tag" '; 
  268. if ( $flag ) 
  269. echo 'class="tab-selected"'; 
  270. echo '>'; 
  271. advantage_widget_field( $this, array ( 'field' => 'tag', 'type' => 'checkbox', 'desc' => __( 'Tag', 'advantage' ), 'ptag' => false, 'class' => 'widget-checkbox' ), $flag ); 
  272. advantage_widget_field( $this, array ( 'field' => 'tag_label', 'type' => 'text', 'ptag' => false, 'class' => '' ), $instance['tag_label'] ); 
  273. echo '</li>'; 
  274. break; 
  275. case 'menu': 
  276. if ( $instance['menu'] > 0 ) 
  277. $flag = 1; 
  278. else 
  279. $flag = 0;  
  280. echo '<li id="tab_menu" '; 
  281. if ( $flag ) 
  282. echo 'class="tab-selected"'; 
  283. echo '>'; 
  284. advantage_widget_field( $this, array ( 'field' => 'menu', 'type' => 'checkbox', 'desc' => __( 'Menu', 'advantage' ), 'ptag' => false, 'class' => 'widget-checkbox' ), $flag ); 
  285. advantage_widget_field( $this, array ( 'field' => 'menu_label', 'type' => 'text', 'ptag' => false, 'class' => '' ), $instance['menu_label'] ); 
  286. advantage_widget_field( $this, array ( 'field' => 'menu_id', 'type' => 'category', 'label' => __( 'Menu:', 'advantage' ), 'label_all' => __( 'Select Menu', 'advantage' ), 'options' => get_terms('nav_menu'), 'ptag' => false ), $instance['menu_id'] ); 
  287. echo '</li>'; 
  288. break; 
  289. case 'text': 
  290. if ( $instance['text'] > 0 ) 
  291. $flag = 1; 
  292. else 
  293. $flag = 0;  
  294. echo '<li id="tab_text" '; 
  295. if ( $flag ) 
  296. echo 'class="tab-selected"'; 
  297. echo '>'; 
  298. advantage_widget_field( $this, array ( 'field' => 'text', 'type' => 'checkbox', 'desc' => __( 'Text', 'advantage' ), 'ptag' => false, 'class' => 'widget-checkbox' ), $flag ); 
  299. advantage_widget_field( $this, array ( 'field' => 'text_label', 'type' => 'text', 'ptag' => false, 'class' => '' ), $instance['text_label'] ); 
  300. echo '</li>'; 
  301. break; 
  302. $instance['data'] = $data; 
  303. ?>  
  304. </ul> 
  305. <?php advantage_widget_field( $this, array ( 'field' => 'limits', 'type' => 'number', 'label' => __( 'Post/Line Limits', 'advantage' ), 'class' => '' ), $instance['limits'] ); 
  306. advantage_widget_field( $this, array ( 'field' => 'showcount', 'type' => 'checkbox', 'desc' => __( 'Show Post Counts', 'advantage' ), 'class' => '' ), $instance['showcount'] ); 
  307. advantage_widget_field( $this, array ( 'field' => 'textcontent', 'type' => 'textarea', 'label' => __( 'Text:', 'advantage' ) ), $instance['textcontent'] ); 
  308. advantage_widget_field( $this, array ( 'field' => 'data', 'type' => 'hidden', 'class' => 'widefat advantagedata', 'ptag' => false ), $instance['data'] );