我被要求在wordpress中创建一个新的下拉菜单。我从来没有用过word press,我也从来没有用php写过代码。我设法为现有的下拉菜单找到了一段代码,但我不明白它是如何工作的。我希望有人能帮我解释一下,这样我就能对发生的事情有所了解了。
<?php if ( is_taxonomy_hierarchical($taxonomy) ) : ?>
    <tr class="form-field term-parent-wrap">
        <th scope="row"><label for="parent"><?php _ex( 'Parent', 'term parent' ); ?></label></th>
        <td>
            <?php
            $dropdown_args = array(
                'hide_empty'       => 0,
                'hide_if_empty'    => false,
                'taxonomy'         => $taxonomy,
                'name'             => 'parent',
                'orderby'          => 'name',
                'selected'         => $tag->parent,
                'exclude_tree'     => $tag->term_id,
                'hierarchical'     => true,
                'show_option_none' => __( 'None' ),
            );
            /** This filter is documented in wp-admin/edit-tags.php */
            $dropdown_args = apply_filters( 'taxonomy_parent_dropdown_args', $dropdown_args, $taxonomy, 'edit' );
            wp_dropdown_categories( $dropdown_args ); ?>
            <?php if ( 'category' == $taxonomy ) : ?>
            <p class="description"><?php _e('Categories, unlike tags, can have a hierarchy. You might have a Jazz category, and under that have children categories for Bebop and Big Band. Totally optional.'); ?></p>
            <?php endif; ?>
        </td>
    </tr>谢谢
发布于 2016-08-11 17:54:38
首先,告诉我们你在寻找什么样的下拉列表。WHat你想在下拉菜单中有吗?因为您的代码当前设置为显示指向您的帖子的类别链接。
如果您阅读了有关此函数的Wordpress codex,并查看您的代码以尝试并遵循它,这可能会更有用。
您还可以尝试更改参数以更改dropdown的输出。
https://codex.wordpress.org/Function_Reference/wp_dropdown_categories
https://stackoverflow.com/questions/38892943
复制相似问题