From: Steve Sutton Date: Tue, 10 Nov 2015 19:45:44 +0000 (-0500) Subject: Upadtes for the menus X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=517438cf6e9ab4083816e793c5e9b3a919db6423;p=web%2FGruntInit%2FglmTheme.git Upadtes for the menus Adding lib directory with navigation and menu walkers files and classes. --- diff --git a/root/functions.php b/root/functions.php index 4868803..e38572a 100644 --- a/root/functions.php +++ b/root/functions.php @@ -1,5 +1,6 @@ 'page', - 'parent' => $parent, - 'number' => '', - 'exclude' => $frontPageId, - 'post_status' => 'publish', - 'sort_order' => 'asc', - 'sort_column' => 'menu_order' - ); - if ($parent == 0 && $menuConfig['menu_options']['main_level_pages']) { - $args['include'] = $menuConfig['menu_options']['main_level_pages']; - } - $pages = get_pages($args); - echo ''."\n"; - foreach ($pages as $page) { - $childs = get_pages('child_of=' . $page->ID); - if (count($childs) > 0) { - echo '
  • '."\n"; - echo ''.$page->post_title.''."\n"; - echo glm_page_menu($page->ID, 'sub-menu dropdown'); - echo '
  • '."\n"; - } else { - echo '
  • '.$page->post_title.'
  • '."\n"; - } - } - echo ''."\n"; -} - -register_nav_menus(array( - 'top-bar' => 'Site Navigation', - //'mobile-off-canvas' => 'Mobile', -// 'footer' => 'Footer' -)); - -if ( ! function_exists( 'feature_top_bar' ) ) { - function feature_top_bar() { - wp_nav_menu(array( - 'container' => false, // remove nav container - 'container_class' => '', // class of container - 'menu' => '', // menu name - 'menu_class' => '', // adding custom nav class - 'theme_location' => 'top-bar', // where it's located in the theme - 'before' => '', // before each link - 'after' => '', // after each link - 'link_before' => '', // before each link text - 'link_after' => '', // after each link text - 'depth' => 3, // limit the depth of the nav - 'fallback_cb' => false, // fallback function (see below) - 'walker' => new Feature_Top_Bar_Walker() - )); - } -} -if ( ! class_exists( 'Feature_Top_Bar_Walker' ) ) : -class Feature_Top_Bar_Walker extends Walker_Nav_Menu { - - function display_element( $element, &$children_elements, $max_depth, $depth = 0, $args, &$output ) { - static $mainLevelCounter; - if ($depth == 0) { - ++$mainLevelCounter; - } - $element->has_children = ! empty( $children_elements[ $element->ID ] ); - $element->classes[] = ( $element->current || $element->current_item_ancestor ) ? 'active' : ''; - $element->classes[] = ( $element->has_children && 1 !== $max_depth ) ? 'has-dropdown' : ''; - $element->classes[] = ( $element->post_parent == 0 && $mainLevelCounter < 6 ) ? '' : 'drop-left'; - parent::display_element( $element, $children_elements, $max_depth, $depth, $args, $output ); - } - - function start_el( &$output, $object, $depth = 0, $args = array(), $current_object_id = 0 ) { - $item_html = ''; - parent::start_el( $item_html, $object, $depth, $args ); - - // Insert style to display page's thumbnail - $item_style = ''; - if ($depth == 0 && has_post_thumbnail((int)$object->object_id)) { - $thumbnail = wp_get_attachment_image_src(get_post_thumbnail_id((int)$object->object_id), 'bpla-drop-down'); - //$item_style .= ""; - } - //$output .= ( 0 == $depth ) ? '
  • ' : ''; - $classes = empty( $object->classes ) ? array() : (array) $object->classes; - if ( in_array( 'label', $classes ) ) { - //$output .= '
  • '; - $item_html = preg_replace( '/]*>(.*)<\/a>/iU', '', $item_html ); - } - if ( in_array( 'divider', $classes ) ) { - $item_html = preg_replace( '/]*>( .* )<\/a>/iU', '', $item_html ); - } - if ($item_style) { - $output .= $item_style; - } - if ($depth == 0 && has_post_thumbnail((int)$object->object_id) && $object->has_children) { - $thumbnail = wp_get_attachment_image_src(get_post_thumbnail_id((int)$object->object_id), 'bpla-drop-down'); - $item_html .= ''; - //$item_html .= '
    ' . print_r($object, true) . '
    '; - } - $output .= $item_html; - } - - function start_lvl( &$output, $depth = 0, $args = array() ) { - if ($depth == 0) { - $output .= "\n
      \n"; - $output .= "\n
    • "; - $output .= "
    • \n"; - } - } - -} -endif; /** * Return the client info option for the given key * @@ -181,20 +49,6 @@ if (!function_exists('glm_get_clientinfo_option')) { } } -/** - * glm_offcanvas_menu - * - * Generate the list of pages as nested ul li list - */ -function glm_offcanvas_menu() -{ - wp_page_menu(array( - 'depth' => 0, - 'sort_column' => 'menu_order', - 'menu_class' => 'left-off-canvas-list' - )); -} - add_theme_support('post-thumbnails'); set_post_thumbnail_size(120, 100, true); /** @@ -253,24 +107,6 @@ function glm_get_header() { // echo ''; // echo ''; - -function glm_side_menu() { - global $post; - $parents = get_post_ancestors($post->ID); - $id = ($parents) ? $parents[count($parents)-1]: $post->ID; - $parent = get_page( $id ); - if ($id == 0) { - $ID = $post->ID; - } else { - $ID = $parent->ID; - } - echo '

      '.get_the_title($ID).'

      '; - echo ''."\n"; -} - - add_action('wp_enqueue_scripts', 'glm_site_scripts'); diff --git a/root/lib/menu-walker.php b/root/lib/menu-walker.php new file mode 100644 index 0000000..64b5a96 --- /dev/null +++ b/root/lib/menu-walker.php @@ -0,0 +1,81 @@ +has_children = ! empty( $children_elements[ $element->ID ] ); + $element->classes[] = ( $element->current || $element->current_item_ancestor ) ? 'active' : ''; + $element->classes[] = ( $element->has_children && 1 !== $max_depth ) ? 'has-dropdown' : ''; + $element->classes[] = ( $element->post_parent == 0 && $mainLevelCounter < 6 ) ? '' : 'drop-left'; + parent::display_element( $element, $children_elements, $max_depth, $depth, $args, $output ); + } + + function start_el( &$output, $object, $depth = 0, $args = array(), $current_object_id = 0 ) { + $item_html = ''; + parent::start_el( $item_html, $object, $depth, $args ); + + // Insert style to display page's thumbnail + $item_style = ''; + if ($depth == 0 && has_post_thumbnail((int)$object->object_id)) { + $thumbnail = wp_get_attachment_image_src(get_post_thumbnail_id((int)$object->object_id), 'large'); + $item_style .= ""; + } + //$output .= ( 0 == $depth ) ? '
    • ' : ''; + $classes = empty( $object->classes ) ? array() : (array) $object->classes; + if ( in_array( 'label', $classes ) ) { + //$output .= '
    • '; + $item_html = preg_replace( '/]*>(.*)<\/a>/iU', '', $item_html ); + } + if ( in_array( 'divider', $classes ) ) { + $item_html = preg_replace( '/]*>( .* )<\/a>/iU', '', $item_html ); + } + if ($item_style) + $output .= $item_style; + $output .= $item_html; + } + + function start_lvl( &$output, $depth = 0, $args = array() ) { + $output .= "\n
        \n"; + } +} +endif; +if ( ! class_exists( 'Glm_Theme_Off_Canvas_Walker' ) ) : +class Glm_Theme_Off_Canvas_Walker extends Walker_Nav_Menu { + function display_element( $element, &$children_elements, $max_depth, $depth = 0, $args, &$output ) { + $element->has_children = ! empty( $children_elements[ $element->ID ] ); + $element->classes[] = ( $element->current || $element->current_item_ancestor ) ? 'active' : ''; + $element->classes[] = ( $element->has_children && 1 !== $max_depth ) ? 'page_item_has_children' : ''; + $element->classes[] = 'page_item'; + + parent::display_element( $element, $children_elements, $max_depth, $depth, $args, $output ); + } + + function start_el( &$output, $object, $depth = 0, $args = array(), $current_object_id = 0 ) { + $item_html = ''; + parent::start_el( $item_html, $object, $depth, $args ); + + $classes = empty( $object->classes ) ? array() : (array) $object->classes; + + if ( in_array( 'label', $classes ) ) { + $item_html = preg_replace( '/]*>(.*)<\/a>/iU', '', $item_html ); + } + + $output .= $item_html; + } + + function start_lvl( &$output, $depth = 0, $args = array() ) { + $output .= "\n
          \n"; + } + + function end_lvl(&$output, $depth = 0, $args = array()){ + $output .= '
        '; + } +} +endif; +?> diff --git a/root/lib/navigation.php b/root/lib/navigation.php new file mode 100644 index 0000000..a47a8a0 --- /dev/null +++ b/root/lib/navigation.php @@ -0,0 +1,155 @@ + 'Site Navigation' +)); + +/** + * Top Bar + */ +if ( ! function_exists( 'glm_theme_top_bar' ) ) { + function glm_theme_top_bar() { + wp_nav_menu(array( + 'container' => false, // remove nav container + 'container_class' => '', // class of container + 'menu' => '', // menu name + 'menu_class' => '', // adding custom nav class + 'theme_location' => 'top-bar', // where it's located in the theme + 'before' => '', // before each link + 'after' => '', // after each link + 'link_before' => '', // before each link text + 'link_after' => '', // after each link text + 'depth' => 3, // limit the depth of the nav + 'fallback_cb' => false, // fallback function (see below) + 'walker' => new Glm_Theme_Top_Bar_Walker() + )); + } +} + +/** + * Mobile off-canvas + */ +if ( ! function_exists( 'glm_theme_mobile_off_canvas' ) ) { + function glm_theme_mobile_off_canvas() { + wp_nav_menu(array( + 'container' => false, // remove nav container + 'container_class' => '', // class of container + 'menu' => '', // menu name + 'menu_class' => 'off-canvas-list', // adding custom nav class + 'theme_location' => 'top-bar', // where it's located in the theme + 'before' => '', // before each link + 'after' => '', // after each link + 'link_before' => '', // before each link text + 'link_after' => '', // after each link text + 'depth' => 5, // limit the depth of the nav + 'fallback_cb' => false, // fallback function (see below) + 'walker' => new Glm_Theme_Off_Canvas_Walker() + )); + } +} + +/** + * Footer + */ +if ( ! function_exists( 'glm_theme_footer' ) ) { + function glm_theme_footer() { + wp_nav_menu(array( + 'container' => false, // remove nav container + 'container_class' => '', // class of container + 'menu' => '', // menu name + 'menu_class' => '', // adding custom nav class + 'theme_location' => 'footer', // where it's located in the theme + 'before' => '', // before each link + 'after' => '', // after each link + 'link_before' => '', // before each link text + 'link_after' => '', // after each link text + 'depth' => 1, // limit the depth of the nav + 'fallback_cb' => false, // fallback function (see below) + )); + } +} + +/** + * glm_page_menu + * + * Grab the top level pages and their sub pages as the main navigation + */ +function glm_page_menu($parent = 0, $class = '') +{ + $menuConfig = glm_get_menu_options(); + $frontPageId = get_option('page_on_front'); + $parents = array(); + $args = array( + 'post_type' => 'page', + 'parent' => $parent, + 'number' => '', + 'exclude' => $frontPageId, + 'post_status' => 'publish', + 'sort_order' => 'asc', + 'sort_column' => 'menu_order' + ); + if ($parent == 0 && $menuConfig['menu_options']['main_level_pages']) { + $args['include'] = $menuConfig['menu_options']['main_level_pages']; + } + $pages = get_pages($args); + echo ''."\n"; + foreach ($pages as $page) { + $childs = get_pages('child_of=' . $page->ID); + if (count($childs) > 0) { + echo '
      • '."\n"; + echo ''.$page->post_title.''."\n"; + echo glm_page_menu($page->ID, 'sub-menu dropdown'); + echo '
      • '."\n"; + } else { + echo '
      • '.$page->post_title.'
      • '."\n"; + } + } + echo '
      '."\n"; +} + +/** + * glm_offcanvas_menu + * + * Generate the list of pages as nested ul li list + */ +function glm_offcanvas_menu() +{ + wp_page_menu(array( + 'depth' => 0, + 'sort_column' => 'menu_order', + 'menu_class' => 'left-off-canvas-list' + )); +} + +/** + * get_menu_options + * + * Grab the menu options from the theme.ini file + */ +function glm_get_menu_options() +{ + static $menu_options; + $themeConfig = get_template_directory() . '/theme.ini'; + + if (!$menu_options && is_file($themeConfig)) { + $menu_options = parse_ini_file($themeConfig, true); + } + return $menu_options; +} + +function glm_side_menu() { + global $post; + $parents = get_post_ancestors($post->ID); + $id = ($parents) ? $parents[count($parents)-1]: $post->ID; + $parent = get_page( $id ); + if ($id == 0) { + $ID = $post->ID; + } else { + $ID = $parent->ID; + } + echo '

      '.get_the_title($ID).'

      '; + echo ''."\n"; +} + diff --git a/root/parts/off-canvas-menu.php b/root/parts/off-canvas-menu.php index c9f9451..6ef952a 100644 --- a/root/parts/off-canvas-menu.php +++ b/root/parts/off-canvas-menu.php @@ -1,4 +1,4 @@ diff --git a/root/parts/top-bar.php b/root/parts/top-bar.php index 8e2bfb3..d34aeb2 100644 --- a/root/parts/top-bar.php +++ b/root/parts/top-bar.php @@ -1,6 +1,6 @@