Advertisement
sc0ttkclark

Pods Menu / List Pages fix

Jul 12th, 2011
331
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.45 KB | None | 0 0
  1. <?php
  2. if (!function_exists('pods_handle_menu')) {
  3.     function pods_handle_menu ($menu_object) {
  4.         $url = current(explode('#', current(explode('?', $_SERVER['REQUEST_URI']))));
  5.         $depth = count(array_filter(explode('/', $url)));
  6.         $url = get_bloginfo('wpurl') . $url;
  7.         foreach ($menu_object as $key => $object) {
  8.             $current_url = $object->url;
  9.             $parsed_url = @parse_url($current_url);
  10.             $current_depth = count(array_filter(explode('/', $parsed_url['path'])));
  11.             if (get_bloginfo('wpurl') . '/' != $object->url && !in_array('current-menu-item', $object->classes) && $url == $object->url)
  12.                 $menu_object[$key]->classes[] = 'current-menu-item';
  13.             if (get_bloginfo('wpurl') . '/' != $object->url && !in_array('current-menu-parent', $object->classes) && false !== strpos($url, $object->url) && 0 == strpos($url, $object->url) && $depth == ($current_depth+1))
  14.                 $menu_object[$key]->classes[] = 'current-menu-parent';
  15.             if (get_bloginfo('wpurl') . '/' != $object->url && !in_array('current-menu-ancestor', $object->classes) && false !== strpos($url, $object->url) && 0 == strpos($url, $object->url))
  16.                 $menu_object[$key]->classes[] = 'current-menu-ancestor';
  17.         }
  18.         return $menu_object;
  19.     }
  20.     add_filter('wp_nav_menu_objects', 'pods_handle_menu', 10, 1);
  21. }
  22.  
  23. if (!function_exists('pods_handle_list_pages')) {
  24.     function pods_handle_list_pages ($output, $r) {
  25.         global $post;
  26.         $current_url = current(explode('#', current(explode('?', $_SERVER['REQUEST_URI']))));
  27.         $real_post = $post;
  28.         $depth = 0;
  29.         $uri = array_filter(explode('/', $current_url));
  30.         $url = get_bloginfo('wpurl') . '/' . implode('/', $uri) . '/';
  31.         if (empty($real_post->ID) || $url != get_permalink($real_post->ID)) {
  32.             $real_post->ID = 0;
  33.             while(0 < strlen(array_pop($uri)) && empty($real_post->ID)) {
  34.                 $depth++;
  35.                 $url = get_bloginfo('wpurl') . '/' . implode('/', $uri) . '/';
  36.                 $real_post_ID = url_to_postid($url);
  37.                 if (0 < $real_post_ID && $url == get_permalink($real_post_ID)) {
  38.                     $real_post = get_post($real_post_ID);
  39.                 }
  40.             }
  41.             if (!function_exists('pixopoint_menu')) {
  42.                 if (0 < $real_post->ID) {
  43.                     if (0 == $depth) {
  44.                         $output = str_replace(' page-item-'. $real_post->ID . ' ', ' page-item-'. $real_post->ID . ' current_page_item ', $output);
  45.                         $output = str_replace(' page-item-'. $real_post->ID . '"', ' page-item-'. $real_post->ID . ' current_page_item"', $output);
  46.                     }
  47.                     elseif (1 == $depth) {
  48.                         $output = str_replace(' page-item-'. $real_post->ID . ' ', ' page-item-'. $real_post->ID . ' current_page_parent ', $output);
  49.                         $output = str_replace(' page-item-'. $real_post->ID . '"', ' page-item-'. $real_post->ID . ' current_page_parent"', $output);
  50.                     }
  51.                     elseif (2 <= $depth) {
  52.                         $output = str_replace(' page-item-'. $real_post->ID . ' ', ' page-item-'. $real_post->ID . ' current_page_ancestor ', $output);
  53.                         $output = str_replace(' page-item-'. $real_post->ID . '"', ' page-item-'. $real_post->ID . ' current_page_ancestor"', $output);
  54.                     }
  55.                     if (0 < $real_post->post_parent) {
  56.                         if (0 == $depth) {
  57.                             $output = str_replace(' page-item-'. $real_post->post_parent . ' ', ' page-item-'. $real_post->post_parent . ' current_page_parent ', $output);
  58.                             $output = str_replace(' page-item-'. $real_post->post_parent . '"', ' page-item-'. $real_post->post_parent . ' current_page_parent"', $output);
  59.                         }
  60.                         elseif (1 <= $depth) {
  61.                             $output = str_replace(' page-item-'. $real_post->post_parent . ' ', ' page-item-'. $real_post->post_parent . ' current_page_ancestor ', $output);
  62.                             $output = str_replace(' page-item-'. $real_post->post_parent . '"', ' page-item-'. $real_post->post_parent . ' current_page_ancestor"', $output);
  63.                         }
  64.                         if (!empty($real_post->ancestors)) {
  65.                             foreach ($real_post->ancestors as $ancestor) {
  66.                                 $output = str_replace(' page-item-'. $ancestor . ' ', ' page-item-'. $ancestor . ' current_page_ancestor ', $output);
  67.                                 $output = str_replace(' page-item-'. $ancestor . '"', ' page-item-'. $ancestor . ' current_page_ancestor"', $output);
  68.                             }
  69.                         }
  70.                     }
  71.                 }
  72.             }
  73.         }
  74.         if (function_exists('pixopoint_menu')) {
  75.             if (0 < $real_post->ID) {
  76.                 if (0 == $depth) {
  77.                     $output = str_replace(' page-item-'. $real_post->ID . ' ', ' page-item-'. $real_post->ID . ' current_page_item ', $output);
  78.                     $output = str_replace(' page-item-'. $real_post->ID . '"', ' page-item-'. $real_post->ID . ' current_page_item"', $output);
  79.                 }
  80.                 elseif (1 == $depth) {
  81.                     $output = str_replace(' page-item-'. $real_post->ID . ' ', ' page-item-'. $real_post->ID . ' current_page_parent ', $output);
  82.                     $output = str_replace(' page-item-'. $real_post->ID . '"', ' page-item-'. $real_post->ID . ' current_page_parent"', $output);
  83.                 }
  84.                 elseif (2 <= $depth) {
  85.                     $output = str_replace(' page-item-'. $real_post->ID . ' ', ' page-item-'. $real_post->ID . ' current_page_ancestor ', $output);
  86.                     $output = str_replace(' page-item-'. $real_post->ID . '"', ' page-item-'. $real_post->ID . ' current_page_ancestor"', $output);
  87.                 }
  88.                 if (0 < $real_post->post_parent) {
  89.                     if (0 == $depth) {
  90.                         $output = str_replace(' page-item-'. $real_post->post_parent . ' ', ' page-item-'. $real_post->post_parent . ' current_page_parent ', $output);
  91.                         $output = str_replace(' page-item-'. $real_post->post_parent . '"', ' page-item-'. $real_post->post_parent . ' current_page_parent"', $output);
  92.                     }
  93.                     elseif (1 <= $depth) {
  94.                         $output = str_replace(' page-item-'. $real_post->post_parent . ' ', ' page-item-'. $real_post->post_parent . ' current_page_ancestor ', $output);
  95.                         $output = str_replace(' page-item-'. $real_post->post_parent . '"', ' page-item-'. $real_post->post_parent . ' current_page_ancestor"', $output);
  96.                     }
  97.                     if (!empty($real_post->ancestors)) {
  98.                         foreach ($real_post->ancestors as $ancestor) {
  99.                             $output = str_replace(' page-item-'. $ancestor . ' ', ' page-item-'. $ancestor . ' current_page_ancestor ', $output);
  100.                             $output = str_replace(' page-item-'. $ancestor . '"', ' page-item-'. $ancestor . ' current_page_ancestor"', $output);
  101.                         }
  102.                     }
  103.                 }
  104.             }
  105.         }
  106.         return $output;
  107.     }
  108.     add_filter('wp_list_pages', 'pods_handle_list_pages', 10, 2);
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement