PageRenderTime 48ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/library/navigation.php

https://gitlab.com/sunielk/foundation-sandbox
PHP | 229 lines | 120 code | 50 blank | 59 comment | 32 complexity | 40386a40b562243c4ff48c2f05bba47e MD5 | raw file
  1. <?php
  2. /**
  3. * Register Menus
  4. *
  5. * @link http://codex.wordpress.org/Function_Reference/register_nav_menus#Examples
  6. * @package FoundationPress
  7. * @since FoundationPress 1.0.0
  8. */
  9. register_nav_menus(array(
  10. 'top-bar-r' => 'Right Top Bar',
  11. 'mobile-nav' => 'Mobile',
  12. ));
  13. /**
  14. * Desktop navigation - right top bar
  15. *
  16. * @link http://codex.wordpress.org/Function_Reference/wp_nav_menu
  17. */
  18. if ( ! function_exists( 'foundationpress_top_bar_r' ) ) {
  19. function foundationpress_top_bar_r() {
  20. wp_nav_menu( array(
  21. 'container' => false,
  22. 'menu_class' => 'dropdown menu',
  23. 'items_wrap' => '<ul id="%1$s" class="%2$s desktop-menu" data-dropdown-menu>%3$s</ul>',
  24. 'theme_location' => 'top-bar-r',
  25. 'depth' => 3,
  26. 'fallback_cb' => false,
  27. 'walker' => new Foundationpress_Top_Bar_Walker(),
  28. ));
  29. }
  30. }
  31. /**
  32. * Mobile navigation - topbar (default) or offcanvas
  33. */
  34. if ( ! function_exists( 'foundationpress_mobile_nav' ) ) {
  35. function foundationpress_mobile_nav() {
  36. wp_nav_menu( array(
  37. 'container' => false, // Remove nav container
  38. 'menu' => __( 'mobile-nav', 'foundationpress' ),
  39. 'menu_class' => 'vertical menu',
  40. 'theme_location' => 'mobile-nav',
  41. 'items_wrap' => '<ul id="%1$s" class="%2$s" data-accordion-menu>%3$s</ul>',
  42. 'fallback_cb' => false,
  43. 'walker' => new Foundationpress_Mobile_Walker(),
  44. ));
  45. }
  46. }
  47. /**
  48. * Add support for buttons in the top-bar menu:
  49. * 1) In WordPress admin, go to Apperance -> Menus.
  50. * 2) Click 'Screen Options' from the top panel and enable 'CSS CLasses' and 'Link Relationship (XFN)'
  51. * 3) On your menu item, type 'has-form' in the CSS-classes field. Type 'button' in the XFN field
  52. * 4) Save Menu. Your menu item will now appear as a button in your top-menu
  53. */
  54. if ( ! function_exists( 'foundationpress_add_menuclass' ) ) {
  55. function foundationpress_add_menuclass( $ulclass ) {
  56. $find = array('/<a rel="button"/', '/<a title=".*?" rel="button"/');
  57. $replace = array('<a rel="button" class="button"', '<a rel="button" class="button"');
  58. return preg_replace( $find, $replace, $ulclass, 1 );
  59. }
  60. add_filter( 'wp_nav_menu','foundationpress_add_menuclass' );
  61. }
  62. /**
  63. * Adapted for Foundation from http://thewebtaylor.com/articles/wordpress-creating-breadcrumbs-without-a-plugin
  64. *
  65. * @param bool $showhome should the breadcrumb be shown when on homepage (only one deactivated entry for home).
  66. * @param bool $separatorclass should a separator class be added (in case :before is not an option).
  67. */
  68. if ( ! function_exists( 'foundationpress_breadcrumb' ) ) {
  69. function foundationpress_breadcrumb( $showhome = true, $separatorclass = false ) {
  70. // Settings
  71. $separator = '&gt;';
  72. $id = 'breadcrumbs';
  73. $class = 'breadcrumbs';
  74. $home_title = 'Homepage';
  75. // Get the query & post information
  76. global $post,$wp_query;
  77. $category = get_the_category();
  78. // Build the breadcrums
  79. echo '<ul id="' . $id . '" class="' . $class . '">';
  80. // Do not display on the homepage
  81. if ( ! is_front_page() ) {
  82. // Home page
  83. echo '<li class="item-home"><a class="bread-link bread-home" href="' . get_home_url() . '" title="' . $home_title . '">' . $home_title . '</a></li>';
  84. if ( $separatorclass ) {
  85. echo '<li class="separator separator-home"> ' . $separator . ' </li>';
  86. }
  87. if ( is_single() ) {
  88. // Single post (Only display the first category)
  89. echo '<li class="item-cat item-cat-' . $category[0]->term_id . ' item-cat-' . $category[0]->category_nicename . '"><a class="bread-cat bread-cat-' . $category[0]->term_id . ' bread-cat-' . $category[0]->category_nicename . '" href="' . get_category_link($category[0]->term_id) . '" title="' . $category[0]->cat_name . '">' . $category[0]->cat_name . '</a></li>';
  90. if ( $separatorclass ) {
  91. echo '<li class="separator separator-' . $category[0]->term_id . '"> ' . $separator . ' </li>';
  92. }
  93. echo '<li class="item-current item-' . $post->ID . '"><strong class="bread-current bread-' . $post->ID . '" title="' . get_the_title() . '">' . get_the_title() . '</strong></li>';
  94. } else if ( is_category() ) {
  95. // Category page
  96. echo '<li class="item-current item-cat-' . $category[0]->term_id . ' item-cat-' . $category[0]->category_nicename . '"><strong class="bread-current bread-cat-' . $category[0]->term_id . ' bread-cat-' . $category[0]->category_nicename . '">' . $category[0]->cat_name . '</strong></li>';
  97. } else if ( is_page() ) {
  98. // Standard page
  99. if ( $post->post_parent ) {
  100. // If child page, get parents
  101. $anc = get_post_ancestors( $post->ID );
  102. // Get parents in the right order
  103. $anc = array_reverse( $anc );
  104. // Parent page loop
  105. $parents = '';
  106. foreach ( $anc as $ancestor ) {
  107. $parents .= '<li class="item-parent item-parent-' . $ancestor . '"><a class="bread-parent bread-parent-' . $ancestor . '" href="' . get_permalink($ancestor) . '" title="' . get_the_title($ancestor) . '">' . get_the_title($ancestor) . '</a></li>';
  108. if ( $separatorclass ) {
  109. $parents .= '<li class="separator separator-' . $ancestor . '"> ' . $separator . ' </li>';
  110. }
  111. }
  112. // Display parent pages
  113. echo $parents;
  114. // Current page
  115. echo '<li class="current item-' . $post->ID . '">' . get_the_title() . '</li>';
  116. } else {
  117. // Just display current page if not parents
  118. echo '<li class="current item-' . $post->ID . '"> ' . get_the_title() . '</li>';
  119. }
  120. } else if ( is_tag() ) {
  121. // Tag page
  122. // Get tag information
  123. $term_id = get_query_var('tag_id');
  124. $taxonomy = 'post_tag';
  125. $args = 'include=' . $term_id;
  126. $terms = get_terms($taxonomy, $args);
  127. // Display the tag name
  128. echo '<li class="current item-tag-' . $terms[0]->term_id . ' item-tag-' . $terms[0]->slug . '">' . $terms[0]->name . '</li>';
  129. } elseif ( is_day() ) {
  130. // Day archive
  131. // Year link
  132. echo '<li class="item-year item-year-' . get_the_time('Y') . '"><a class="bread-year bread-year-' . get_the_time('Y') . '" href="' . get_year_link(get_the_time('Y')) . '" title="' . get_the_time('Y') . '">' . get_the_time('Y') . ' Archives</a></li>';
  133. if ( $separatorclass ) {
  134. echo '<li class="separator separator-' . get_the_time('Y') . '"> ' . $separator . ' </li>';
  135. }
  136. // Month link
  137. echo '<li class="item-month item-month-' . get_the_time('m') . '"><a class="bread-month bread-month-' . get_the_time('m') . '" href="' . get_month_link(get_the_time('Y'), get_the_time('m')) . '" title="' . get_the_time('M') . '">' . get_the_time('M') . ' Archives</a></li>';
  138. if ( $separatorclass ) {
  139. echo '<li class="separator separator-' . get_the_time('m') . '"> ' . $separator . ' </li>';
  140. }
  141. // Day display
  142. echo '<li class="current item-' . get_the_time('j') . '">' . get_the_time('jS') . ' ' . get_the_time('M') . ' Archives</li>';
  143. } else if ( is_month() ) {
  144. // Month Archive
  145. // Year link
  146. echo '<li class="item-year item-year-' . get_the_time('Y') . '"><a class="bread-year bread-year-' . get_the_time('Y') . '" href="' . get_year_link(get_the_time('Y')) . '" title="' . get_the_time('Y') . '">' . get_the_time('Y') . ' Archives</a></li>';
  147. if ( $separatorclass ) {
  148. echo '<li class="separator separator-' . get_the_time('Y') . '"> ' . $separator . ' </li>';
  149. }
  150. // Month display
  151. echo '<li class="item-month item-month-' . get_the_time('m') . '">' . get_the_time('M') . ' Archives</li>';
  152. } else if ( is_year() ) {
  153. // Display year archive
  154. echo '<li class="current item-current-' . get_the_time('Y') . '">' . get_the_time('Y') . ' Archives</li>';
  155. } else if ( is_author() ) {
  156. // Auhor archive
  157. // Get the author information
  158. global $author;
  159. $userdata = get_userdata($author);
  160. // Display author name
  161. echo '<li class="current item-current-' . $userdata->user_nicename . '">Author: ' . $userdata->display_name . '</li>';
  162. } else if ( get_query_var('paged') ) {
  163. // Paginated archives
  164. echo '<li class="current item-current-' . get_query_var('paged') . '">'.__('Page') . ' ' . get_query_var('paged') . '</li>';
  165. } else if ( is_search() ) {
  166. // Search results page
  167. echo '<li class="current item-current-' . get_search_query() . '">Search results for: ' . get_search_query() . '</li>';
  168. } elseif ( is_404() ) {
  169. // 404 page
  170. echo '<li>Error 404</li>';
  171. }
  172. } else {
  173. if ( $showhome ) {
  174. echo '<li class="item-home current">' . $home_title . '</li>';
  175. }
  176. }
  177. echo '</ul>';
  178. }
  179. }