开发者

Wordpress and custom menu using wp_page_menu

开发者 https://www.devze.com 2023-01-08 10:57 出处:网络
I\'m using the following code to add custom taxonomies to my menu in wordpress.I need to make these \"sub\" items under Products.

I'm using the following code to add custom taxonomies to my menu in wordpress. I need to make these "sub" items under Products.

Example right now they are showing up:

Photography > Lighting
Photography > Cameras

I need them to show up as

Products > Photography > Lighting
Products > Photography > Cameras

add_filter( 'wp_page_menu', 'custom_page_nav', 90 );
function custom_page_nav( $menu )
{
    $taxonomy = 'catalog';
    $orderby = 'name';
    $show_count = 0; // 1 for yes, 0 for no
    $pad_counts = 1; // 1 for yes, 0 for no
    $hierarchical = true; // 1 for yes, 0 for no
    $title = '';

    $args = array( 'taxonomy' => $taxonomy, 'orderby' => $orderby, 'show_c开发者_开发问答ount' => $show_count, 'pad_counts' => $pad_counts,
        'hierarchical' => $hierarchical, 'title_li' => false, 'echo' => false, 'empty' => true, 'hide_empty' => false,
        'depth' => 0 );
    $links .= wp_list_categories( $args );
    //  $links .= wp_list_categories( array( 'title_li' => false, 'echo' => false, 'empty' => true ) );
    $menu = str_replace( '', $links . '', $menu );
    return $menu;
}



function custom_page_nav( $menu ){
    $taxonomy = 'catalog';
    $orderby = 'name';
    $show_count = 0; // 1 for yes, 0 for no
    $pad_counts = 1; // 1 for yes, 0 for no
    $hierarchical = 1; // 1 for yes, 0 for no
    $title = '';

    $args = array( 'taxonomy' => $taxonomy, 'orderby' => $orderby, 'show_count' => $show_count, 'pad_counts' => $pad_counts,
        'hierarchical' => $hierarchical, 'title_li' => false, 'echo' => false, 'empty' => true, 'hide_empty' => true,
        'depth' => 0 );
    $links .= wp_list_categories( $args );
    //  $links .= wp_list_categories( array( 'title_li' => false, 'echo' => false, 'empty' => true ) );
    $menu = str_replace( '', 'Prodcuts '.$links . '', $menu ); 
    //
    return $menu;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消