Revision: 46836
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at May 26, 2011 09:04 by ablears
Initial Code
//Our custom sitemap which reads the menu order using extended menu walker class //Shortcode function wdp_shortcode_sitemap($atts){ //[sitemap] extract(shortcode_atts(array( ), $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; $indent = ( $depth ) ? str_repeat( "\t", $depth ) : ''; $id=strtolower(str_replace(" ","-",$item->title)); $id=str_replace(array('&','&'),"",$id); $id=str_replace('--',"-",$id); $output .= $indent . '<li id="sitemap-'. $id . '"' . $value .'>'; $attributes = ! empty( $item->attr_title ) ? ' title="' . esc_attr( $item->attr_title ) .'"' : ''; $attributes .= ! empty( $item->target ) ? ' target="' . esc_attr( $item->target ) .'"' : ''; $attributes .= ! empty( $item->xfn ) ? ' rel="' . esc_attr( $item->xfn ) .'"' : ''; $attributes .= ! empty( $item->url ) ? ' href="' . esc_attr( $item->url ) .'"' : ''; //$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 ); } }
Initial URL
Initial Description
Use a shortcode [sitemap] to render a sitemap ordered by custom menu order (Wordpress 3+).
Initial Title
Wordpress custom sitemap shortcode following custom menu order
Initial Tags
wordpress, order
Initial Language
PHP