【问题标题】:DropDown Navigation for Custom Post Types?自定义帖子类型的下拉导航?
【发布时间】:2015-04-29 10:52:26
【问题描述】:

我正在尝试在 WordPress 中的导航上创建一个下拉菜单,使用自定义帖子类型类别作为下拉菜单。例如,在产品中,我有 6 个不同的类别:

Category A
Category B
Category C
Category D
Category E
Category F

如果我转到外观 > 菜单,我可以选择勾选我的类别并将它们添加到菜单中。当我这样做时,我得到以下信息:

有没有简单的解决方案?

【问题讨论】:

    标签: php html css wordpress navigation


    【解决方案1】:

    您需要使用 get_categories 并滚动您自己的菜单,而不使用 menu_nav() 函数。

    <?php
    $args=array(
    'post_type'                => 'category',
    'child_of'                 => 0,
    'parent'                   => '',
    'orderby'                  => 'name',
    'order'                    => 'ASC',
    'hide_empty'               => 1,
    'hierarchical'             => 1,
    'exclude'                  => '',
    'include'                  => '',
    'number'                   => '',
    'pad_counts'               => false
    );
    
    $categories=get_categories($args);
    echo '<ul>';
    foreach ( $categories as $category ) {
    if ( $category->parent > 0 ) {
        continue;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多