wp_dropdown_categories自定义分类查看全部

时间:2017-10-13 11:07:17

标签: wordpress custom-taxonomy

我有一个名为'projects'的自定义帖子类型。

附加到这是一个名为'type'的自定义分类。

在“项目”和“类型”存档页面上,我有一个下拉列表,按分类术语(类型)过滤循环结果。

这些工作正常,除了顶部的“查看全部”选项,点击时不提交表单,所以什么也没做。

有什么想法吗?

archive-projects.php&中的代码分类法type.php ...

                    <?php $args = array(
                        'show_option_all'    => 'All',
                        'hide_empty'         => 0,
                        'class'              => 'selectpicker',
                        'taxonomy'           => 'type',
                        'hide_if_empty'      => false,
                        'value_field'        => 'slug',
                    ); ?>

                    <?php wp_dropdown_categories( $args ); ?>
                    <script type="text/javascript">
                        var dropdown = document.getElementById("cat");
                        function onCatChange() {
                            if ( dropdown.options[dropdown.selectedIndex].value != -1 ) {
                                location.href = "<?php echo esc_url( home_url( '/projects/' ) ); ?>/"+dropdown.options[dropdown.selectedIndex].value;
                            }
                        }
                        dropdown.onchange = onCatChange;
                    </script>

...的functions.php

  $projectLabels = array(
      'name' => _x('Projects', 'post type general name'),
      'singular_name' => _x('All Projects', 'post type singular name'),
      'all_items' => 'All Projects',
      'add_new' => _x('Add New', 'Project'),
      'add_new_item' => __("Add New Project"),
      'edit_item' => __("Edit Project"),
      'new_item' => __("New Project"),
      'view_item' => __("View Project"),
      'search_items' => __("Search Projects"),
      'not_found' =>  __('No Project(s) found'),
      'not_found_in_trash' => __('No Project(s) found in Trash'),
      'parent_item_colon' => ''
    );
    $projectArgs = array(
      'labels' => $projectLabels,
      'public' => true,
      'publicly_queryable' => true,
      'show_ui' => true,
      'query_var' => true,
      'rewrite' => array( 'slug' => 'projects', 'with_front' => false ),
      'capability_type' => 'post',
      'hierarchical' => true,
      'menu_position' => null,
      'supports' => array('title','editor','revisions','thumbnail','custom-fields'),
      'menu_icon' => 'dashicons-building',
      'has_archive' => true
    );
    register_post_type('projects',$projectArgs);



    // taxonomy
    add_action( 'init', 'create_project_tax' );

    function create_project_tax() {
        register_taxonomy(
            'type',
            'projects',
            array(
                'label' => __( 'Types' ),
                'rewrite' => array( 'slug' => 'projects' ),
                'hierarchical' => true,
            )
        );
    }

0 个答案:

没有答案