/ Published in: PHP
Use a shortcode [sitemap] to render a sitemap ordered by custom menu order (Wordpress 3+).
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
//Our custom sitemap which reads the menu order using extended menu walker class //Shortcode function wdp_shortcode_sitemap($atts){ //[sitemap] ), $atts)); //call the function $shortcodecontent = wdp_sitemap(); return $shortcodecontent; } add_shortcode('sitemap', 'wdp_shortcode_sitemap'); //call the menu and use our custom walker function wdp_sitemap(){ return wp_nav_menu(array('theme_location' => 'primary', 'walker' => new wdp_sitemap_walker(), 'fallback_cb' => '', 'echo'=>false)); } //extended navigation class for sitemap rendering class wdp_sitemap_walker extends Walker_Nav_Menu { function start_el(&$output, $item, $depth, $args) { global $wp_query; $output .= $indent . '<li id="sitemap-'. $id . '"' . $value .'>'; //$item_output .= $args->before; $item_output .= '<a'. $attributes .'>'; $item_output .= $args->link_before .$prepend.apply_filters( 'the_title', $item->title, $item->ID ).$append; // $item_output .= $args->link_after; $item_output .= '</a>'; //$item_output .= $args->after; $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args ); } }