本文整理汇总了PHP中walk_category_dropdown_tree函数的典型用法代码示例。如果您正苦于以下问题:PHP walk_category_dropdown_tree函数的具体用法?PHP walk_category_dropdown_tree怎么用?PHP walk_category_dropdown_tree使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了walk_category_dropdown_tree函数的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: meta_box_ms_categories
public static function meta_box_ms_categories()
{
global $EM_Event;
EM_Object::ms_global_switch();
$categories = EM_Categories::get(array('hide_empty' => false));
?>
<?php
if (count($categories) > 0) {
?>
<p class="ms-global-categories">
<?php
$selected = $EM_Event->get_categories()->get_ids();
?>
<?php
$walker = new EM_Walker_Category();
?>
<?php
$args_em = array('hide_empty' => 0, 'name' => 'event_categories[]', 'hierarchical' => true, 'id' => EM_TAXONOMY_CATEGORY, 'taxonomy' => EM_TAXONOMY_CATEGORY, 'selected' => $selected, 'walker' => $walker);
?>
<?php
echo walk_category_dropdown_tree($categories, 0, $args_em);
?>
</p>
<?php
} else {
?>
<p><?php
sprintf(__('No categories available, <a href="%s">create one here first</a>', 'dbem'), get_bloginfo('wpurl') . '/wp-admin/admin.php?page=events-manager-categories');
?>
</p>
<?php
}
?>
<!-- END Categories -->
<?php
EM_Object::ms_global_switch_back();
}
示例2: wp_dropdown_categories
function wp_dropdown_categories($args = '')
{
if (is_array($args)) {
$r =& $args;
} else {
parse_str($args, $r);
}
$defaults = array('show_option_all' => '', 'show_option_none' => '', 'orderby' => 'ID', 'order' => 'ASC', 'show_last_update' => 0, 'show_count' => 0, 'hide_empty' => 1, 'child_of' => 0, 'exclude' => '', 'echo' => 1, 'selected' => 0, 'hierarchical' => 0, 'name' => 'cat', 'class' => 'postform');
$defaults['selected'] = is_category() ? get_query_var('cat') : 0;
$r = array_merge($defaults, $r);
$r['include_last_update_time'] = $r['show_last_update'];
extract($r);
$categories = get_categories($r);
$output = '';
if (!empty($categories)) {
$output = "<select name='{$name}' id='{$name}' class='{$class}'>\n";
if ($show_option_all) {
$show_option_all = apply_filters('list_cats', $show_option_all);
$output .= "\t<option value='0'>{$show_option_all}</option>\n";
}
if ($show_option_none) {
$show_option_none = apply_filters('list_cats', $show_option_none);
$output .= "\t<option value='-1'>{$show_option_none}</option>\n";
}
if ($hierarchical) {
$depth = 0;
} else {
$depth = -1;
}
// Flat.
$output .= walk_category_dropdown_tree($categories, $depth, $r);
$output .= "</select>\n";
}
$output = apply_filters('wp_dropdown_cats', $output);
if ($echo) {
echo $output;
}
return $output;
}
示例3: wp_dropdown_categories
//.........这里部分代码省略.........
* 'slug', 'term_group', 'term_taxonomy_id', 'taxonomy', 'description',
* 'parent', 'count'. Default 'term_id'.
* @type string|array $taxonomy Name of the category or categories to retrieve. Default 'category'.
* @type bool $hide_if_empty True to skip generating markup if no categories are found.
* Default false (create select element even if no categories are found).
* @type bool $required Whether the `<select>` element should have the HTML5 'required' attribute.
* Default false.
* }
* @return string HTML content only if 'echo' argument is 0.
*/
function wp_dropdown_categories($args = '')
{
$defaults = array('show_option_all' => '', 'show_option_none' => '', 'orderby' => 'id', 'order' => 'ASC', 'show_count' => 0, 'hide_empty' => 1, 'child_of' => 0, 'exclude' => '', 'echo' => 1, 'selected' => 0, 'hierarchical' => 0, 'name' => 'cat', 'id' => '', 'class' => 'postform', 'depth' => 0, 'tab_index' => 0, 'taxonomy' => 'category', 'hide_if_empty' => false, 'option_none_value' => -1, 'value_field' => 'term_id', 'required' => false);
$defaults['selected'] = is_category() ? get_query_var('cat') : 0;
// Back compat.
if (isset($args['type']) && 'link' == $args['type']) {
/* translators: 1: "type => link", 2: "taxonomy => link_category" alternative */
_deprecated_argument(__FUNCTION__, '3.0.0', sprintf(__('%1$s is deprecated. Use %2$s instead.'), '<code>type => link</code>', '<code>taxonomy => link_category</code>'));
$args['taxonomy'] = 'link_category';
}
$r = wp_parse_args($args, $defaults);
$option_none_value = $r['option_none_value'];
if (!isset($r['pad_counts']) && $r['show_count'] && $r['hierarchical']) {
$r['pad_counts'] = true;
}
$tab_index = $r['tab_index'];
$tab_index_attribute = '';
if ((int) $tab_index > 0) {
$tab_index_attribute = " tabindex=\"{$tab_index}\"";
}
// Avoid clashes with the 'name' param of get_terms().
$get_terms_args = $r;
unset($get_terms_args['name']);
$categories = get_terms($r['taxonomy'], $get_terms_args);
$name = esc_attr($r['name']);
$class = esc_attr($r['class']);
$id = $r['id'] ? esc_attr($r['id']) : $name;
$required = $r['required'] ? 'required' : '';
if (!$r['hide_if_empty'] || !empty($categories)) {
$output = "<select {$required} name='{$name}' id='{$id}' class='{$class}' {$tab_index_attribute}>\n";
} else {
$output = '';
}
if (empty($categories) && !$r['hide_if_empty'] && !empty($r['show_option_none'])) {
/**
* Filters a taxonomy drop-down display element.
*
* A variety of taxonomy drop-down display elements can be modified
* just prior to display via this filter. Filterable arguments include
* 'show_option_none', 'show_option_all', and various forms of the
* term name.
*
* @since 1.2.0
*
* @see wp_dropdown_categories()
*
* @param string $element Taxonomy element to list.
*/
$show_option_none = apply_filters('list_cats', $r['show_option_none']);
$output .= "\t<option value='" . esc_attr($option_none_value) . "' selected='selected'>{$show_option_none}</option>\n";
}
if (!empty($categories)) {
if ($r['show_option_all']) {
/** This filter is documented in wp-includes/category-template.php */
$show_option_all = apply_filters('list_cats', $r['show_option_all']);
$selected = '0' === strval($r['selected']) ? " selected='selected'" : '';
$output .= "\t<option value='0'{$selected}>{$show_option_all}</option>\n";
}
if ($r['show_option_none']) {
/** This filter is documented in wp-includes/category-template.php */
$show_option_none = apply_filters('list_cats', $r['show_option_none']);
$selected = selected($option_none_value, $r['selected'], false);
$output .= "\t<option value='" . esc_attr($option_none_value) . "'{$selected}>{$show_option_none}</option>\n";
}
if ($r['hierarchical']) {
$depth = $r['depth'];
// Walk the full depth.
} else {
$depth = -1;
// Flat.
}
$output .= walk_category_dropdown_tree($categories, $depth, $r);
}
if (!$r['hide_if_empty'] || !empty($categories)) {
$output .= "</select>\n";
}
/**
* Filters the taxonomy drop-down output.
*
* @since 2.1.0
*
* @param string $output HTML output.
* @param array $r Arguments used to build the drop-down.
*/
$output = apply_filters('wp_dropdown_cats', $output, $r);
if ($r['echo']) {
echo $output;
}
return $output;
}
示例4: _e
<?php
/*
* This file is called by templates/forms/location-editor.php to display fields for uploading images on your event form on your website. This does not affect the admin featured image section.
* You can override this file by copying it to /wp-content/themes/yourtheme/plugins/events-manager/forms/event/ and editing it there.
*/
global $EM_Event;
/* @var $EM_Event EM_Event */
$categories = EM_Categories::get(array('orderby' => 'name', 'hide_empty' => 0));
if (count($categories) > 0) {
?>
<div class="event-categories">
<!-- START Categories -->
<label for="event_categories[]"><?php
_e('Category:', 'dbem');
?>
</label>
<select name="event_categories[]" multiple size="10">
<?php
$selected = $EM_Event->get_categories()->get_ids();
$walker = new EM_Walker_CategoryMultiselect();
$args_em = array('hide_empty' => 0, 'name' => 'event_categories[]', 'hierarchical' => true, 'id' => EM_TAXONOMY_CATEGORY, 'taxonomy' => EM_TAXONOMY_CATEGORY, 'selected' => $selected, 'walker' => $walker);
echo walk_category_dropdown_tree($categories, 0, $args_em);
?>
</select>
<!-- END Categories -->
</div>
<?php
}
示例5: byrd_selectCategories
function byrd_selectCategories($args = array())
{
$defaults = array('show_option_all' => '', 'show_option_none' => '', 'orderby' => 'id', 'order' => 'ASC', 'show_last_update' => 0, 'show_count' => 0, 'hide_empty' => 1, 'child_of' => 0, 'exclude' => '', 'echo' => 0, 'selected' => 0, 'hierarchical' => 0, 'name' => 'cat', 'class' => 'postform', 'depth' => 0, 'multiple' => 5, 'tab_index' => 0);
$defaults['selected'] = is_category() ? get_query_var('cat') : 0;
$r = wp_parse_args($args, $defaults);
$r['include_last_update_time'] = $r['show_last_update'];
extract($r);
$tab_index_attribute = '';
if ((int) $tab_index > 0) {
$tab_index_attribute = " tabindex=\"{$tab_index}\"";
}
$categories = get_categories($r);
$name = esc_attr($name);
$class = esc_attr($class);
$output = '';
if (!empty($categories)) {
$output = "<select name='{$name}' id='{$name}' class='{$class}' {$tab_index_attribute}";
if ($multiple) {
$output .= " multiple size=\"" . $multiple . "\" style=\"height: 10em;\"";
}
$output .= ">\n";
if ($show_option_all) {
$show_option_all = apply_filters('list_cats', $show_option_all);
$selected = '0' === strval($r['selected']) ? " selected='selected'" : '';
$output .= "\t<option value='0'{$selected}>{$show_option_all}</option>\n";
}
if ($show_option_none) {
$show_option_none = apply_filters('list_cats', $show_option_none);
$selected = '-1' === strval($r['selected']) ? " selected='selected'" : '';
$output .= "\t<option value='-1'{$selected}>{$show_option_none}</option>\n";
}
if ($hierarchical) {
$depth = $r['depth'];
} else {
$depth = -1;
}
// Flat.
$output .= walk_category_dropdown_tree($categories, $depth, $r);
$output .= "</select>\n";
}
$output = apply_filters('byrd_selectCategories', $output);
if ($echo) {
echo $output;
}
return $output;
}
示例6: avh_wp_dropdown_categories
/**
* Display or retrieve the HTML dropdown list of categories.
*
* The list of arguments is below:
* 'show_option_all' (string) - Text to display for showing all categories.
* 'show_option_none' (string) - Text to display for showing no categories.
* 'orderby' (string) default is 'ID' - What column to use for ordering the
* categories.
* 'order' (string) default is 'ASC' - What direction to order categories.
* 'show_last_update' (bool|int) default is 0 - See {@link get_categories()}
* 'show_count' (bool|int) default is 0 - Whether to show how many posts are
* in the category.
* 'hide_empty' (bool|int) default is 1 - Whether to hide categories that
* don't have any posts attached to them.
* 'child_of' (int) default is 0 - See {@link get_categories()}.
* 'exclude' (string) - See {@link get_categories()}.
* 'echo' (bool|int) default is 1 - Whether to display or retrieve content.
* 'depth' (int) - The max depth.
* 'tab_index' (int) - Tab index for select element.
* 'name' (string) - The name attribute value for selected element.
* 'class' (string) - The class attribute value for selected element.
* 'selected' (int) - Which category ID is selected.
*
* The 'hierarchical' argument, which is disabled by default, will override the
* depth argument, unless it is true. When the argument is false, it will
* display all of the categories. When it is enabled it will use the value in
* the 'depth' argument.
*
* @since 2.1.0
*
* @param string|array $args Optional. Override default arguments.
* @return string HTML content only if 'echo' argument is 0.
*/
function avh_wp_dropdown_categories($args = '', $selectedonly)
{
$mywalker = new AVH_Walker_CategoryDropdown();
$defaults = array('show_option_all' => '', 'show_option_none' => '', 'orderby' => 'id', 'order' => 'ASC', 'show_last_update' => 0, 'show_count' => 0, 'hide_empty' => 1, 'child_of' => 0, 'exclude' => '', 'echo' => 1, 'selected' => 0, 'hierarchical' => 0, 'name' => 'cat', 'class' => 'postform', 'depth' => 0, 'tab_index' => 0, 'walker' => $mywalker);
$defaults['selected'] = is_category() ? get_query_var('cat') : 0;
$r = wp_parse_args($args, $defaults);
if (!isset($r['pad_counts']) && $r['show_count'] && $r['hierarchical']) {
$r['pad_counts'] = true;
}
$r['include_last_update_time'] = $r['show_last_update'];
extract($r);
$tab_index_attribute = '';
if ((int) $tab_index > 0) {
$tab_index_attribute = ' tabindex="' . $tab_index . '"';
}
$categories = get_categories($r);
$name = esc_attr($name);
$class = esc_attr($class);
$output = '';
if (!empty($categories)) {
$output = '<select name="' . $name . '" id="' . $name . '" class="' . $class . '" ' . $tab_index_attribute . '>' . "\n";
if ($show_option_all) {
$show_option_all = apply_filters('list_cats', $show_option_all);
$selected = '0' === strval($r['selected']) ? " selected='selected'" : '';
$output .= "\t" . '<option value="0"' . $selected . '>' . $show_option_all . '</option>' . "\n";
}
if ($show_option_none) {
$show_option_none = apply_filters('list_cats', $show_option_none);
$selected = '-1' === strval($r['selected']) ? " selected='selected'" : '';
$output .= "\t" . '<option value="-1"' . $selected . '>' . $show_option_none . '</option>' . "\n";
}
if ($hierarchical) {
$depth = $r['depth'];
// Walk the full depth.
} else {
$depth = -1;
// Flat
}
$output .= walk_category_dropdown_tree($categories, $depth, $r);
$output .= "</select>\n";
}
$output = apply_filters('wp_dropdown_cats', $output);
if ($echo) {
echo $output;
}
return $output;
}
示例7: wp_dropdown_categories
/**
* Display or retrieve the HTML dropdown list of categories.
*
* The list of arguments is below:
* 'show_option_all' (string) - Text to display for showing all categories.
* 'show_option_none' (string) - Text to display for showing no categories.
* 'orderby' (string) default is 'ID' - What column to use for ordering the
* categories.
* 'order' (string) default is 'ASC' - What direction to order categories.
* 'show_count' (bool|int) default is 0 - Whether to show how many posts are
* in the category.
* 'hide_empty' (bool|int) default is 1 - Whether to hide categories that
* don't have any posts attached to them.
* 'child_of' (int) default is 0 - See {@link get_categories()}.
* 'exclude' (string) - See {@link get_categories()}.
* 'echo' (bool|int) default is 1 - Whether to display or retrieve content.
* 'depth' (int) - The max depth.
* 'tab_index' (int) - Tab index for select element.
* 'name' (string) - The name attribute value for select element.
* 'id' (string) - The ID attribute value for select element. Defaults to name if omitted.
* 'class' (string) - The class attribute value for select element.
* 'selected' (int) - Which category ID is selected.
* 'taxonomy' (string) - The name of the taxonomy to retrieve. Defaults to category.
*
* The 'hierarchical' argument, which is disabled by default, will override the
* depth argument, unless it is true. When the argument is false, it will
* display all of the categories. When it is enabled it will use the value in
* the 'depth' argument.
*
* @since 2.1.0
*
* @param string|array $args Optional. Override default arguments.
* @return string HTML content only if 'echo' argument is 0.
*/
function wp_dropdown_categories($args = '')
{
$defaults = array('show_option_all' => '', 'show_option_none' => '', 'orderby' => 'id', 'order' => 'ASC', 'show_count' => 0, 'hide_empty' => 1, 'child_of' => 0, 'exclude' => '', 'echo' => 1, 'selected' => 0, 'hierarchical' => 0, 'name' => 'cat', 'id' => '', 'class' => 'postform', 'depth' => 0, 'tab_index' => 0, 'taxonomy' => 'category', 'hide_if_empty' => false);
$defaults['selected'] = is_category() ? get_query_var('cat') : 0;
// Back compat.
if (isset($args['type']) && 'link' == $args['type']) {
_deprecated_argument(__FUNCTION__, '3.0', '');
$args['taxonomy'] = 'link_category';
}
$r = wp_parse_args($args, $defaults);
if (!isset($r['pad_counts']) && $r['show_count'] && $r['hierarchical']) {
$r['pad_counts'] = true;
}
extract($r);
$tab_index_attribute = '';
if ((int) $tab_index > 0) {
$tab_index_attribute = " tabindex=\"{$tab_index}\"";
}
$categories = get_terms($taxonomy, $r);
$name = esc_attr($name);
$class = esc_attr($class);
$id = $id ? esc_attr($id) : $name;
if (!$r['hide_if_empty'] || !empty($categories)) {
$output = "<select name='{$name}' id='{$id}' class='{$class}' {$tab_index_attribute}>\n";
} else {
$output = '';
}
if (empty($categories) && !$r['hide_if_empty'] && !empty($show_option_none)) {
$show_option_none = apply_filters('list_cats', $show_option_none);
$output .= "\t<option value='-1' selected='selected'>{$show_option_none}</option>\n";
}
if (!empty($categories)) {
if ($show_option_all) {
$show_option_all = apply_filters('list_cats', $show_option_all);
$selected = '0' === strval($r['selected']) ? " selected='selected'" : '';
$output .= "\t<option value='0'{$selected}>{$show_option_all}</option>\n";
}
if ($show_option_none) {
$show_option_none = apply_filters('list_cats', $show_option_none);
$selected = '-1' === strval($r['selected']) ? " selected='selected'" : '';
$output .= "\t<option value='-1'{$selected}>{$show_option_none}</option>\n";
}
if ($hierarchical) {
$depth = $r['depth'];
} else {
$depth = -1;
}
// Flat.
$output .= walk_category_dropdown_tree($categories, $depth, $r);
}
if (!$r['hide_if_empty'] || !empty($categories)) {
$output .= "</select>\n";
}
$output = apply_filters('wp_dropdown_cats', $output);
if ($echo) {
echo $output;
}
return $output;
}
示例8: aviators_dropdown_categories
function aviators_dropdown_categories($args = '')
{
$defaults = array('show_option_all' => '', 'show_option_none' => '', 'orderby' => 'id', 'order' => 'ASC', 'show_count' => 0, 'hide_empty' => 1, 'child_of' => 0, 'exclude' => '', 'echo' => 1, 'selected' => 0, 'hierarchical' => 0, 'name' => 'cat', 'id' => '', 'class' => 'postform', 'depth' => 0, 'tab_index' => 0, 'taxonomy' => 'category', 'hide_if_empty' => false, 'parent' => '');
// Back compat.
if (isset($args['type']) && 'link' == $args['type']) {
_deprecated_argument(__FUNCTION__, '3.0', '');
$args['taxonomy'] = 'link_category';
}
$r = wp_parse_args($args, $defaults);
if (!isset($r['pad_counts']) && $r['show_count'] && $r['hierarchical']) {
$r['pad_counts'] = true;
}
extract($r);
$tab_index_attribute = '';
if ((int) $tab_index > 0) {
$tab_index_attribute = " tabindex=\"{$tab_index}\"";
}
$categories = get_terms($taxonomy, $r);
$name = esc_attr($name);
$class = esc_attr($class);
$id = $id ? esc_attr($id) : $name;
if (!$r['hide_if_empty'] || !empty($categories)) {
$output = "<select name='{$name}' id='{$id}' class='{$class}' {$tab_index_attribute}>\n";
} else {
$output = '';
}
if (empty($categories) && !$r['hide_if_empty'] && !empty($show_option_none)) {
/**
* Filter a taxonomy drop-down display element.
*
* A variety of taxonomy drop-down display elements can be modified
* just prior to display via this filter. Filterable arguments include
* 'show_option_none', 'show_option_all', and various forms of the
* term name.
*
* @since 1.2.0
*
* @see wp_dropdown_categories()
*
* @param string $element Taxonomy element to list.
*/
$show_option_none = apply_filters('list_cats', $show_option_none);
$output .= "\t<option value='-1' selected='selected'>{$show_option_none}</option>\n";
}
if (!empty($categories)) {
if ($show_option_all) {
/** This filter is documented in wp-includes/category-template.php */
$show_option_all = apply_filters('list_cats', $show_option_all);
$selected = '0' === strval($r['selected']) ? " selected='selected'" : '';
$output .= "\t<option value='0'{$selected}>{$show_option_all}</option>\n";
}
if ($show_option_none) {
/** This filter is documented in wp-includes/category-template.php */
$show_option_none = apply_filters('list_cats', $show_option_none);
$selected = '-1' === strval($r['selected']) ? " selected='selected'" : '';
$output .= "\t<option value='-1'{$selected}>{$show_option_none}</option>\n";
}
$output .= walk_category_dropdown_tree($categories, $depth, $r);
}
if (!$r['hide_if_empty'] || !empty($categories)) {
$output .= "</select>\n";
}
/**
* Filter the taxonomy drop-down output.
*
* @since 2.1.0
*
* @param string $output HTML output.
* @param array $r Arguments used to build the drop-down.
*/
$output = apply_filters('wp_dropdown_cats', $output, $r);
if ($echo) {
echo $output;
}
return $output;
}
示例9: form
public function form($instance)
{
$instance = array_merge(array('titles' => array(), 'cats' => array(0), 'number' => 4, 'cat' => 0, 'tax_tags' => array()), $instance);
extract($instance);
?>
<style>
.widget-content p.separator { padding-top: 10px; border-top: 1px solid #d8d8d8; }
.widget-content .tax_tag { display: none; }
</style>
<div id="tab-options">
<script type="text/html" class="template-tab-options">
<p class="title separator">
<label><?php
printf(__('Tab #%s Title:', 'bunyad-widgets'), '<span>%n%</span>');
?>
</label>
<input class="widefat" name="<?php
echo esc_attr($this->get_field_name('titles'));
?>
[%n%]" type="text" value="%title%" />
</p>
<div class="cat">
<label><?php
printf(__('Tab #%s Category:', 'bunyad-widgets'), '<span>%n%</span>');
?>
</label>
<?php
$r = array('orderby' => 'name', 'hierarchical' => 1, 'selected' => $cat, 'show_count' => 0);
// categories list
$cats_list = walk_category_dropdown_tree(get_terms('category', $r), 0, $r);
// custom options
$options = apply_filters('bunyad_widget_tabbed_recent_options', array('recent' => __('Recent Posts', 'bunyad-widgets'), 'popular' => __('Popular Posts', 'bunyad-widgets'), 'top-reviews' => __('Top Reviews', 'bunyad-widgets'), 'comments' => __('Recent Comments', 'bunyad-widgets'), 'tag' => __('Use a Tag', 'bunyad-widgets')));
?>
<select name="<?php
echo $this->get_field_name('cats') . '[%n%]';
?>
">
<?php
foreach ($options as $key => $val) {
?>
<option value="<?php
echo esc_attr($key);
?>
"<?php
echo $cat == $key ? ' selected' : '';
?>
><?php
echo esc_html($val);
?>
</option>
<?php
}
?>
<optgroup label="<?php
_e('Category', 'bunyad-widgets');
?>
">
<?php
echo $cats_list;
?>
</optgroup>
</select>
<div class="tax_tag">
<p><label><?php
printf(__('Tab #%s Tag:', 'bunyad-widgets'), '<span>%n%</span>');
?>
</label> <input type="text" name="<?php
echo esc_attr($this->get_field_name('tax_tags'));
?>
[%n%]" value="%tax_tag%" /></p>
</div>
<p><?php
_e('Posts:', 'bunyad');
?>
<input name="<?php
echo $this->get_field_name('posts');
?>
[%n%]" type="text" value="%posts%" size="3" /></p>
<p><a href="#" class="remove-recent-tab">[x] <?php
_e('remove', 'bunyad-widgets');
?>
</a></p>
</div>
</script>
//.........这里部分代码省略.........
示例10: avh_wp_dropdown_categories
//.........这里部分代码省略.........
* @type string $option_none_value Value to use when no category is selected. Default empty.
* @type string $orderby Which column to use for ordering categories. See get_terms() for a list
* of accepted values. Default 'id' (term_id).
* @type string $order Whether to order terms in ascending or descending order. Accepts 'ASC'
* or 'DESC'. Default 'ASC'.
* @type bool $pad_counts See get_terms() for an argument description. Default false.
* @type bool|int $show_count Whether to include post counts. Accepts 0, 1, or their bool equivalents.
* Default 0.
* @type bool|int $hide_empty Whether to hide categories that don't have any posts. Accepts 0, 1, or
* their bool equivalents. Default 1.
* @type int $child_of Term ID to retrieve child terms of. See get_terms(). Default 0.
* @type array|string $exclude Array or comma/space-separated string of term ids to exclude.
* If `$include` is non-empty, `$exclude` is ignored. Default empty
* array.
* @type bool|int $echo Whether to echo or return the generated markup. Accepts 0, 1, or their
* bool equivalents. Default 1.
* @type bool|int $hierarchical Whether to traverse the taxonomy hierarchy. Accepts 0, 1, or their bool
* equivalents. Default 0.
* @type int $depth Maximum depth. Default 0.
* @type int $tab_index Tab index for the select element. Default 0 (no tabindex).
* @type string $name Value for the 'name' attribute of the select element. Default 'cat'.
* @type string $id Value for the 'id' attribute of the select element. Defaults to the value
* of `$name`.
* @type string $class Value for the 'class' attribute of the select element. Default
* 'postform'.
* @type int|string $selected Value of the option that should be selected. Default 0.
* @type string $value_field Term field that should be used to populate the 'value' attribute
* of the option elements. Accepts any valid term field: 'term_id',
* 'name',
* 'slug', 'term_group', 'term_taxonomy_id', 'taxonomy', 'description',
* 'parent', 'count'. Default 'term_id'.
* @type string|array $taxonomy Name of the category or categories to retrieve. Default 'category'.
* @type bool $hide_if_empty True to skip generating markup if no categories are found.
* Default false (create select element even if no categories are found).
* }
* @return string HTML content only if 'echo' argument is 0.
*/
public function avh_wp_dropdown_categories($args = '')
{
$mywalker = new AVH_Walker_CategoryDropdown();
// @format_off
$defaults = array('show_option_all' => '', 'show_option_none' => '', 'orderby' => 'id', 'order' => 'ASC', 'show_last_update' => 0, 'show_count' => 0, 'hide_empty' => 1, 'child_of' => 0, 'exclude' => '', 'echo' => 1, 'selected' => 0, 'hierarchical' => 0, 'name' => 'cat', 'id' => '', 'class' => 'postform', 'depth' => 0, 'tab_index' => 0, 'taxonomy' => 'category', 'walker' => $mywalker, 'hide_if_empty' => false, 'option_none_value' => -1, 'value_field' => 'term_id');
// @format_on
$defaults['selected'] = is_category() ? get_query_var('cat') : 0;
$r = wp_parse_args($args, $defaults);
$option_none_value = $r['option_none_value'];
if (!isset($r['pad_counts']) && $r['show_count'] && $r['hierarchical']) {
$r['pad_counts'] = true;
}
$r['include_last_update_time'] = $r['show_last_update'];
$tab_index = $r['tab_index'];
$tab_index_attribute = '';
if ((int) $tab_index > 0) {
$tab_index_attribute = ' tabindex="' . $tab_index . '"';
}
// Avoid clashes with the 'name' param of get_terms().
$get_terms_args = $r;
unset($get_terms_args['name']);
$categories = get_terms($r['taxonomy'], $get_terms_args);
$name = esc_attr($r['name']);
$class = esc_attr($r['class']);
$id = $r['id'] ? esc_attr($r['id']) : $name;
if (!$r['hide_if_empty'] || !empty($categories)) {
$output = "<select name='{$name}' id='{$id}' class='{$class}' {$tab_index_attribute}>\n";
} else {
$output = '';
}
if (empty($categories) && !$r['hide_if_empty'] && !empty($r['show_option_none'])) {
$show_option_none = apply_filters('list_cats', $r['show_option_none']);
$output .= "\t<option value='-1' selected='selected'>{$show_option_none}</option>\n";
}
if (!empty($categories)) {
if ($r['show_option_all']) {
$show_option_all = apply_filters('list_cats', ${$r}['show_option_all']);
$selected = '0' === strval($r['selected']) ? " selected='selected'" : '';
$output .= "\t" . '<option value="0"' . $selected . '>' . $show_option_all . '</option>' . "\n";
}
if ($r['show_option_none']) {
$show_option_none = apply_filters('list_cats', $r['show_option_none']);
$selected = selected($option_none_value, $r['selected'], false);
$output .= "\t" . '<option value="' . esc_attr($option_none_value) . '"' . $selected . '>' . $show_option_none . '</option>' . "\n";
}
if ($r['hierarchical']) {
$depth = $r['depth'];
// Walk the full depth.
} else {
$depth = -1;
// Flat
}
$output .= walk_category_dropdown_tree($categories, $depth, $r);
}
if (!$r['hide_if_empty'] || !empty($categories)) {
$output .= "</select>\n";
}
$output = apply_filters('wp_dropdown_cats', $output, $r);
if ($r['echo']) {
echo $output;
}
return $output;
}
示例11: gdtt_dropdown_taxonomy_terms
/**
* Display or retrieve the HTML dropdown list of terms for any taxonomy.
*
* @param string|array $args Optional. Override default arguments.
* @return string HTML content only if 'echo' argument is 0.
*/
function gdtt_dropdown_taxonomy_terms($args = array())
{
$defaults = array('show_option_all' => '', 'show_option_none' => '', 'orderby' => 'id', 'order' => 'ASC', 'show_last_update' => 0, 'show_count' => 0, 'hide_empty' => 1, 'child_of' => 0, 'exclude' => '', 'echo' => 1, 'selected' => 0, 'hierarchical' => 0, 'name' => 'cat', 'id' => '', 'class' => 'postform', 'depth' => 0, 'tab_index' => 0, 'taxonomy' => 'category', 'hide_if_empty' => false);
$r = wp_parse_args($args, $defaults);
if (!isset($r['pad_counts']) && $r['show_count'] && $r['hierarchical']) {
$r['pad_counts'] = true;
}
$r['include_last_update_time'] = $r['show_last_update'];
extract($r);
$tab_index_attribute = '';
if ((int) $tab_index > 0) {
$tab_index_attribute = " tabindex=\"{$tab_index}\"";
}
$terms = get_terms($taxonomy, $r);
$name = esc_attr($name);
$class = esc_attr($class);
$id = $id ? esc_attr($id) : $name;
if (!$r['hide_if_empty'] || !empty($terms)) {
$output = "<select name='{$name}' id='{$id}' class='{$class}' {$tab_index_attribute}>\n";
} else {
$output = '';
}
if (empty($terms) && !$r['hide_if_empty'] && !empty($show_option_none)) {
$show_option_none = apply_filters('list_cats', $show_option_none);
$output .= "\t<option value='-1' selected='selected'>{$show_option_none}</option>\n";
}
if (!empty($terms)) {
if ($show_option_all) {
$show_option_all = apply_filters('list_cats', $show_option_all);
$selected = '0' === strval($r['selected']) ? " selected='selected'" : '';
$output .= "\t<option value='0'{$selected}>{$show_option_all}</option>\n";
}
if ($show_option_none) {
$show_option_none = apply_filters('list_cats', $show_option_none);
$selected = '-1' === strval($r['selected']) ? " selected='selected'" : '';
$output .= "\t<option value='-1'{$selected}>{$show_option_none}</option>\n";
}
if ($hierarchical) {
$depth = $r['depth'];
} else {
$depth = -1;
}
$r["walker"] = new gdttWalker_TermsDropdown();
$output .= walk_category_dropdown_tree($terms, $depth, $r);
}
if (!$r['hide_if_empty'] || !empty($terms)) {
$output .= "</select>\n";
}
$output = apply_filters('wp_dropdown_terms_' . $taxonomy, $output);
if ($echo) {
echo $output;
}
return $output;
}
示例12: wp_dropdown_categories
/**
* Display or retrieve the HTML dropdown list of categories.
*
* The list of arguments is below:
* 'show_option_all' (string) - Text to display for showing all categories.
* 'show_option_none' (string) - Text to display for showing no categories.
* 'orderby' (string) default is 'ID' - What column to use for ordering the
* categories.
* 'order' (string) default is 'ASC' - What direction to order categories.
* 'show_last_update' (bool|int) default is 0 - See {@link get_categories()}
* 'show_count' (bool|int) default is 0 - Whether to show how many posts are
* in the category.
* 'hide_empty' (bool|int) default is 1 - Whether to hide categories that
* don't have any posts attached to them.
* 'child_of' (int) default is 0 - See {@link get_categories()}.
* 'exclude' (string) - See {@link get_categories()}.
* 'echo' (bool|int) default is 1 - Whether to display or retrieve content.
* 'depth' (int) - The max depth.
* 'tab_index' (int) - Tab index for select element.
* 'name' (string) - The name attribute value for selected element.
* 'class' (string) - The class attribute value for selected element.
* 'selected' (int) - Which category ID is selected.
*
* The 'hierarchical' argument, which is disabled by default, will override the
* depth argument, unless it is true. When the argument is false, it will
* display all of the categories. When it is enabled it will use the value in
* the 'depth' argument.
*
* @since 2.1.0
*
* @param string|array $args Optional. Override default arguments.
* @return string HTML content only if 'echo' argument is 0.
*/
function wp_dropdown_categories( $args = '' ) {
$defaults = array(
'show_option_all' => '', 'show_option_none' => '',
'orderby' => 'ID', 'order' => 'ASC',
'show_last_update' => 0, 'show_count' => 0,
'hide_empty' => 1, 'child_of' => 0,
'exclude' => '', 'echo' => 1,
'selected' => 0, 'hierarchical' => 0,
'name' => 'cat', 'class' => 'postform',
'depth' => 0, 'tab_index' => 0
);
$defaults['selected'] = ( is_category() ) ? get_query_var( 'cat' ) : 0;
$r = wp_parse_args( $args, $defaults );
$r['include_last_update_time'] = $r['show_last_update'];
extract( $r );
$tab_index_attribute = '';
if ( (int) $tab_index > 0 )
$tab_index_attribute = " tabindex=\"$tab_index\"";
$categories = get_categories( $r );
$output = '';
if ( ! empty( $categories ) ) {
$output = "<select name='$name' id='$name' class='$class' $tab_index_attribute>\n";
if ( $show_option_all ) {
$show_option_all = apply_filters( 'list_cats', $show_option_all );
$output .= "\t<option value='0'>$show_option_all</option>\n";
}
if ( $show_option_none ) {
$show_option_none = apply_filters( 'list_cats', $show_option_none );
$output .= "\t<option value='-1'>$show_option_none</option>\n";
}
if ( $hierarchical )
$depth = $r['depth']; // Walk the full depth.
else
$depth = -1; // Flat.
$output .= walk_category_dropdown_tree( $categories, $depth, $r );
$output .= "</select>\n";
}
$output = apply_filters( 'wp_dropdown_cats', $output );
if ( $echo )
echo $output;
return $output;
}
示例13: deposquare_do_page
function deposquare_do_page()
{
global $depo_post_types;
if (esc_attr($_POST['action']) == 'update') {
foreach ($depo_post_types as $key => $option) {
if (esc_attr($_POST[$option['id']])) {
update_option($option['id'], esc_attr($_POST[$option['id']]));
}
}
}
foreach ($depo_post_types as $key => $option) {
register_setting('deposquareops', $option['id'], 'intval');
}
?>
<div class="wrap">
<h2><?php
_e('DePo Square Theme Options');
?>
</h2>
<form method="post">
<?php
settings_fields('deposquareops');
?>
<?php
$defaults = array('show_option_all' => '', 'show_option_none' => '', 'orderby' => 'id', 'order' => 'ASC', 'show_last_update' => 0, 'show_count' => 0, 'hide_empty' => 1, 'child_of' => 0, 'exclude' => '', 'echo' => 1, 'selected' => 0, 'hierarchical' => 0, 'name' => 'cat', 'class' => 'postform', 'depth' => 0, 'tab_index' => 0);
$args = array('hide_empty' => 0, 'name' => 'category_parent', 'orderby' => 'name', 'selected' => $category->parent, 'hierarchical' => true, 'show_option_none' => __('None'));
$r = wp_parse_args($args, $defaults);
extract($r);
$categories = get_categories($args);
?>
<table class="form-table">
<tr valign="top">
<th scope="row">Category Mappings</th>
</tr>
<tr>
<td>
<table border="0" cellspacing="5" cellpadding="5">
<tr><th><strong>Type of Post</strong></th> <th><strong>Category to Map</strong></th></tr>
<?php
foreach ($depo_post_types as $key => $option) {
if ($key != 'post') {
?>
<tr><td><?php
_e($option['proper_name']);
?>
</td><td>
<?php
$value = get_option($option['id']);
?>
<select name="<?php
echo $option['id'];
?>
" id="<?php
echo $option['id'];
?>
" size="1">
<?php
/*foreach($categories as $catkey => $data) { ?>
<option <?php if( $value == $data->cat_ID) echo ' selected="selected"'; ?>
value="<?php echo $data->cat_ID; ?>">
<?php if( $data->parent > 0 ) { $pad .= ' '; } else { $pad = ''; } ?>
<?php echo $pad.$data->category_nicename; ?>
</option>
<?php } */
?>
<?php
$output = '';
$output .= walk_category_dropdown_tree($categories, $r['depth'], $r);
if ($value > 0) {
$output = preg_replace('/(value="' . $value . '")/', '$1' . ' selected="selected"', $output);
}
echo $output;
?>
</select>
<?php
$value = 0;
?>
</td></tr>
<?php
}
}
?>
</table>
</td>
</tr>
</table>
<p class="submit">
<input type="submit" class="button-primary" value="<?php
_e('Save Changes');
?>
" />
</p>
</form>
</div>
<?php
}
示例14: esc_html
?>
<td class = "pll-language-column"><?php
echo esc_html($language->name);
?>
</td>
<td class = "pll-edit-column"><?php
echo $link;
?>
</td><?php
} else {
?>
<td class = "pll-language-column"><?php
echo $language->flag ? $language->flag : esc_html($language->slug);
?>
</td><?php
}
?>
<td class = "pll-translation-column"><?php
printf('<select name="term_tr_lang[%1$s]" id="tr_lang_%1$s"><option value="">%2$s</option>%3$s</select>', esc_attr($language->slug), __('None'), walk_category_dropdown_tree($translations, 0, array('selected' => empty($translation) ? 0 : $translation->term_id, 'show_count' => 0)));
?>
</td>
</tr><?php
}
// foreach
?>
</table><?php
if (isset($term_id)) {
// edit term form
?>
</td><?php
}