WordPress 和使用 wp_page_menu 的自定义菜单

发布于 2024-09-11 02:08:44 字数 1121 浏览 0 评论 0原文

我使用以下代码将自定义分类法添加到 WordPress 的菜单中。我需要在产品下制作这些“子”项目。

现在他们出现的例子:

Photography > Lighting
Photography > Cameras

我需要他们出现

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_count' => $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;
}

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_count' => $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;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

棒棒糖 2024-09-18 02:08:44

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;
}

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;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文