本文整理汇总了PHP中wp_dropdown_categories函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_dropdown_categories函数的具体用法?PHP wp_dropdown_categories怎么用?PHP wp_dropdown_categories使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wp_dropdown_categories函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: render_content
public function render_content()
{
$dropdown = wp_dropdown_categories(array('name' => '_customize-dropdown-categories-' . $this->id, 'echo' => 0, 'show_option_all' => __('— All Categories —', 'scoutwp-theme'), 'selected' => $this->value()));
// Add in the link
$dropdown = str_replace('<select', '<select ' . $this->get_link(), $dropdown);
echo "<label class='customize-control-select'><span class='customize-control-title'>{$this->label}</span><span class='description customize-control-description'>{$this->description}</span> {$dropdown}</label>";
}
开发者ID:ajgamble-milner,项目名称:scoutwp_theme,代码行数:7,代码来源:class-customize-category-control.php
示例2: extra_tablenav
function extra_tablenav($which)
{
global $post_type_object, $cat;
$term_id = 0;
?>
<div class="alignleft actions"> <?php
if ('top' == $which && !is_singular()) {
$this->months_dropdown(self::$post_type);
if (is_object_in_taxonomy(self::$post_type, SI_Record::TAXONOMY)) {
$term_id = isset($_GET[SI_Record::TAXONOMY]) ? $_GET[SI_Record::TAXONOMY] : 0;
$dropdown_options = array('taxonomy' => SI_Record::TAXONOMY, 'show_option_all' => __('View all types'), 'hide_empty' => 0, 'hierarchical' => 1, 'show_count' => 0, 'orderby' => 'name', 'selected' => $term_id, 'name' => SI_Record::TAXONOMY);
wp_dropdown_categories($dropdown_options);
}
do_action('restrict_manage_posts');
submit_button(__('Filter'), 'secondary', false, false, array('id' => 'post-query-submit'));
// Purge
if (count($this->items) > 0) {
if (isset($_GET[SI_Record::TAXONOMY]) && $_GET[SI_Record::TAXONOMY]) {
$term = get_term($_GET[SI_Record::TAXONOMY], SI_Record::TAXONOMY);
$button_label = __('Purge') . ' ' . $term->name . ' ' . __('Type');
}
$button_label = isset($button_label) ? $button_label : __('Purge All Types');
printf('<button type="submit" name="purge_records" class="button" value="%s">%s</button>', $term_id, $button_label);
printf('<input type="hidden" name="%s" value="%s" />', SI_Internal_Records::RECORD_PURGE_NONCE, wp_create_nonce(SI_Internal_Records::RECORD_PURGE_NONCE));
}
}
?>
</div> <?php
}
开发者ID:danielbachhuber,项目名称:marcgratch.com,代码行数:30,代码来源:Records_Admin_Table.php
示例3: jbst_taxonomy_select
function jbst_taxonomy_select($field, $meta)
{
wp_dropdown_categories(array('show_option_none' => 'Default', 'hierarchical' => 1, 'taxonomy' => $field['taxonomy'], 'orderby' => 'name', 'hide_empty' => 0, 'name' => $field['id'], 'selected' => $meta));
if (!empty($field['desc'])) {
echo '<p class="cmb_metabox_description">' . $field['desc'] . '</p>';
}
}
开发者ID:jwlayug,项目名称:jbst,代码行数:7,代码来源:template-metaboxes.php
示例4: widget
/**
* Outputs the HTML for this widget.
*
* @param array $args An array of standard parameters for widgets in this theme
* @param array $instance An array of settings for this widget instance
*
* @return void Echoes it's output
*/
public function widget($args, $instance)
{
$instance = wp_parse_args($instance, $this->defaults);
extract($args);
if ($title = apply_filters('widget_title', $instance['title'], $instance, $this->id_base)) {
echo $before_title . esc_html($title) . $after_title;
}
echo $before_widget;
?>
<form method="get" action="<?php
echo esc_url(home_url('/'));
?>
" class="<?php
echo $instance['instance'] ? 'instance-search' : '';
?>
">
<div class="product-cat">
<?php
wp_dropdown_categories(array('name' => 'product_cat', 'taxonomy' => 'product_cat', 'class' => 'cs-select cs-skin-elastic', 'orderby' => 'NAME', 'order' => 'ASC', 'hierarchical' => 1, 'hide_empty' => 0, 'show_option_all' => __('All Categories', 'bigboom'), 'walker' => new TA_Cat_Slug_Walker()));
?>
</div>
<input type="text" name="s" class="search-field" placeholder="Search the entire shop.....">
<input type="hidden" name="post_type" value="product">
<input type="submit" value="<?php
esc_attr_e('Search', 'bigboom');
?>
" class="search-submit">
</form>
<?php
echo $after_widget;
}
开发者ID:Qualitair,项目名称:ecommerce,代码行数:41,代码来源:product-search.php
示例5: html
public function html($meta, $repeatable = null)
{
is_array($meta) and $meta = null;
$name = is_null($repeatable) ? $this->_name : $this->_name . '[' . $repeatable . ']';
$id = is_null($repeatable) ? $this->_id : $this->_id . '_' . $repeatable;
$classes = array();
if (!empty($this->_params['context']) and $this->_params['context'] != 'side') {
$classes[] = 'form-field';
}
$classes = implode(' ', $classes);
empty($classes) or $classes = ' class="' . $classes . '"';
$args = array('id' => $id, 'name' => $name, 'selected' => $meta, 'echo' => 0, 'class' => $classes);
empty($this->_params['args']) or $args = array_merge($args, $this->_params['args']);
echo '<tr' . $classes . '>';
echo '
<th scope="row">
<label for="' . $id . '">' . $this->_label . '</label>
</th>
<td>
' . wp_dropdown_categories($args) . '
<p class="description">' . $this->_description . '</p>
</td>';
echo '</tr>';
}
开发者ID:daidais,项目名称:morepress,代码行数:25,代码来源:Term.php
示例6: formCreate
function formCreate($instance,$headline_instance, $cat_instance, $dropdown_instance,$num_post_instance){
//Generates widget options form which you see in the widgets section in the admin
$headline = esc_attr($instance[$headline_instance]);
$include_cats = esc_attr($instance[$cat_instance]);
$num_post_selected = esc_attr($instance[$num_post_instance]);
?>
<p><label for="<? echo $this->get_field_id($headline_instance); ?>">Headline:
<input class="widefat"
id="<? echo $this->get_field_id($headline_instance); ?>"
name="<? echo $this->get_field_name($headline_instance); ?>"
type="text"
value="<? echo attribute_escape($headline); ?>" />
</label>
</p>
<p>
Categories Dropdown / How Many Posts<br />
<? wp_dropdown_categories('orderby=name&hide_empty=0&show_option_none=Select Categories to include&id='.$dropdown_instance.'&name='.$dropdown_instance.'&taxonomy=category'); echo " "; echo $this->dw_createNumSelect($this->get_field_id($num_post_instance),$this->get_field_name($num_post_instance),10,$num_post_selected);?> <br /><br />
<label for="<? echo $this->get_field_id($cat_instance); ?>">Included Categories:
<textarea class="widefat"
id="<? echo $this->get_field_id($cat_instance); ?>"
name="<? echo $this->get_field_name($cat_instance); ?>"
rows="2"
cols="1" style="text-align:left;"><? echo attribute_escape($include_cats); ?></textarea>
</label>
</p>
<?
}
开发者ID:GraphicLingoes,项目名称:codesamples,代码行数:28,代码来源:homepage_loops.php
示例7: show_ajax_form
public function show_ajax_form()
{
if (isset($_REQUEST['productid'])) {
$dropdownargs = array('show_option_all' => false, 'show_option_none' => false, 'orderby' => 'id', 'order' => 'ASC', 'show_count' => 1, 'hide_empty' => 0, 'child_of' => 0, 'exclude' => '', 'echo' => 0, 'selected' => 0, 'hierarchical' => 1, 'name' => 'wcordersortupdateshelf', 'id' => '', 'class' => 'postform', 'depth' => 0, 'tab_index' => 0, 'taxonomy' => 'product_shelf', 'hide_if_empty' => false, 'option_none_value' => -1, 'value_field' => 'term_id');
$echo = '';
$product_name = '<a href="' . get_post_permalink($_REQUEST['productid']) . '" >' . get_the_title($_REQUEST['productid']) . '</a>';
$echo .= '<form method="post"> <table class="flat-table" cellspacing="3" >';
$echo .= '<tr>';
$echo .= '<th>Product Name : </th>';
$echo .= '<td>' . $product_name . '</td>';
$echo .= '</tr>';
$echo .= '<tr>';
$echo .= '<th>Shelf : </th>';
$echo .= '<td>' . wp_dropdown_categories($dropdownargs) . '</td>';
$echo .= '</tr>';
$echo .= '<tr>';
$echo .= '<td><input type="hidden" name="action" value="wcordersortforechangeshelf" /> </td>';
$echo .= '<td><input type="submit" class="myButton "value="Update Shelf"/> </td>';
$echo .= '</tr>';
$echo .= '</table> </form>';
$echo .= '<style>';
$echo .= 'table { width: 100%; }
th { background: #eee; color: black; font-weight: bold; }
td, th { padding: 6px; border: 1px solid #ccc; text-align: left; }';
$echo .= ".myButton {\tbackground:-webkit-gradient(linear, left top, left bottom, color-stop(0.05, #77b55a), color-stop(1, #72b352)); background:-moz-linear-gradient(top, #77b55a 5%, #72b352 100%); \tbackground:-webkit-linear-gradient(top, #77b55a 5%, #72b352 100%); \tbackground:-o-linear-gradient(top, #77b55a 5%, #72b352 100%); background:-ms-linear-gradient(top, #77b55a 5%, #72b352 100%); background:linear-gradient(to bottom, #77b55a 5%, #72b352 100%); filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#77b55a', endColorstr='#72b352',GradientType=0); background-color:#77b55a; -moz-border-radius:4px; \t-webkit-border-radius:4px; \tborder-radius:4px; \tborder:1px solid #4b8f29; display:inline-block; cursor:pointer; color:#ffffff; font-family:Arial; font-size:15px; font-weight:bold; padding:6px 12px;\ttext-decoration:none;\ttext-shadow:0px 1px 0px #5b8a3c;} .myButton:hover { background:-webkit-gradient(linear, left top, left bottom, color-stop(0.05, #72b352), color-stop(1, #77b55a)); \tbackground:-moz-linear-gradient(top, #72b352 5%, #77b55a 100%); \tbackground:-webkit-linear-gradient(top, #72b352 5%, #77b55a 100%); \tbackground:-o-linear-gradient(top, #72b352 5%, #77b55a 100%); \tbackground:-ms-linear-gradient(top, #72b352 5%, #77b55a 100%); \tbackground:linear-gradient(to bottom, #72b352 5%, #77b55a 100%); filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#72b352', endColorstr='#77b55a',GradientType=0); \tbackground-color:#72b352; } .myButton:active { \tposition:relative; \ttop:1px; }";
$echo .= '</style>';
echo $echo;
}
wp_die();
}
开发者ID:technofreaky,项目名称:wc-order-category-sort,代码行数:30,代码来源:class-admin-functions.php
示例8: render_content
public function render_content()
{
$dropdown = wp_dropdown_categories(array('name' => $this->id, 'echo' => 0, 'show_option_all' => __('All', 'matheson'), 'selected' => $this->value(), 'class' => 'customize-dropdown-cats'));
// hackily add in the data link parameter.
$dropdown = str_replace('<select', '<select ' . $this->get_link(), $dropdown);
printf('<label class="customize-control-select"><span class="customize-control-title">%s</span> %s</label>', $this->label, $dropdown);
}
开发者ID:HandsomeDogStudio,项目名称:peanutbutterplan,代码行数:7,代码来源:customizer.php
示例9: job_manager_job_filters_search_jobs_end
/**
* Add the field to the filters
*/
public function job_manager_job_filters_search_jobs_end($atts)
{
if ((!isset($atts['selected_region']) || '' == $atts['selected_region']) && isset($_GET['search_region'])) {
$atts['selected_region'] = absint($_GET['search_region']);
}
wp_dropdown_categories(apply_filters('job_manager_regions_dropdown_args', array('show_option_all' => __('All Regions', 'wp-job-manager-locations'), 'hierarchical' => true, 'taxonomy' => 'job_listing_region', 'name' => 'search_region', 'class' => 'search_region', 'orderby' => 'name', 'order' => 'ASC', 'hide_empty' => 0, 'selected' => isset($atts['selected_region']) ? $atts['selected_region'] : '')));
}
开发者ID:Atlas-Solutions-Group,项目名称:wp-job-manager-locations,代码行数:10,代码来源:class-template.php
示例10: build_taxo_dd_filter
function build_taxo_dd_filter()
{
$tax_name = $this->name;
$tax_obj = get_taxonomy($tax_name);
$selected = empty($_GET[$tax_name]) ? '' : $_GET[$tax_name];
wp_dropdown_categories(array('show_option_all' => __('Show All ' . $tax_obj->label . ' '), 'taxonomy' => $tax_name, 'name' => $tax_obj->name, 'orderby' => 'name', 'selected' => $selected, 'hierarchical' => $tax_obj->hierarchical, 'show_count' => false, 'hide_empty' => false));
}
开发者ID:srolland,项目名称:dev,代码行数:7,代码来源:qqp_ctax.php
示例11: render_content
/**
* Render the control's content.
*
* @since 3.4.0
*/
public function render_content()
{
$dropdown = wp_dropdown_categories(array('name' => '_customize-dropdown-categories-' . $this->id, 'echo' => 0, 'show_option_none' => __('— Select —'), 'option_none_value' => '0', 'selected' => $this->value()));
// Hackily add in the data link parameter.
$dropdown = str_replace('<select', '<select ' . $this->get_link(), $dropdown);
printf('<label class="customize-control-select"><span class="customize-control-title">%s</span> %s</label>', $this->label, $dropdown);
}
开发者ID:tosbey1,项目名称:Nimbly,代码行数:12,代码来源:wp_customize.php
示例12: sbc_shortcode
function sbc_shortcode($atts)
{
extract(shortcode_atts(array(' ' => null), $atts));
$args = array('show_option_none' => 'Select category', 'show_count' => 1, 'orderby' => 'name', 'echo' => 1, 'child_of' => tb_get_option('main_course_select'), 'class' => 'form-control subject');
?>
<section class="course-finder">
<h6 class="section-heading text-highlight"><span class="line">Course Finder</span></h1>
<div class="section-content">
<form class="course-finder-form" action="<?php
echo esc_url(home_url('/'));
?>
" method="get">
<div class="row">
<div class="col-md-5 col-sm-5 subject">
<?php
wp_dropdown_categories($args);
?>
</div>
<div class="col-md-7 col-sm-7 keywords">
<input type="text" class="form-control pull-left" name="s" id="s" placeholder="Search keywords" />
<button type="submit" class="btn btn-theme">
<i class="fa fa-search"></i>
</button>
</div>
</div>
<input type="hidden" name="post_type" value="courses" />
</form><!--//course-finder-form-->
<a class="read-more" href="<?php
echo esc_url(get_permalink(get_page_by_title('Courses')));
?>
">View all our courses<i class="fa fa-chevron-right"></i></a>
</div><!--//section-content-->
</section><!--//course-finder-->
<?php
}
开发者ID:allenahner,项目名称:wp,代码行数:35,代码来源:shortcode.php
示例13: restrict_contacts_by_status
public static function restrict_contacts_by_status()
{
global $typenow;
if (Sprout_Client::POST_TYPE === $typenow) {
$selected = 0;
$taxonomy = Sprout_Client::TYPE_TAXONOMY;
if (isset($_GET[$taxonomy]) && $_GET[$taxonomy]) {
$term = get_term_by('slug', $_GET[$taxonomy], $taxonomy);
$selected = $term->term_id;
}
$status_taxonomy = get_taxonomy($taxonomy);
wp_dropdown_categories(array('show_option_all' => sprintf(self::__('All %s'), $status_taxonomy->label), 'taxonomy' => $taxonomy, 'name' => $taxonomy, 'orderby' => 'name', 'selected' => $selected, 'show_count' => true, 'value_field' => 'slug'));
$type_selected = 0;
$taxonomy = Sprout_Client::STATUS_TAXONOMY;
if (isset($_GET[$taxonomy]) && $_GET[$taxonomy]) {
$term = get_term_by('slug', $_GET[$taxonomy], $taxonomy);
$type_selected = $term->term_id;
}
$status_taxonomy = get_taxonomy($taxonomy);
wp_dropdown_categories(array('show_option_all' => sprintf(self::__('All %s'), $status_taxonomy->label), 'taxonomy' => $taxonomy, 'name' => $taxonomy, 'orderby' => 'name', 'selected' => $type_selected, 'show_count' => true, 'value_field' => 'slug'));
if ($selected || $type_selected) {
$url = add_query_arg(array('post_type' => Sprout_Client::POST_TYPE), admin_url('edit.php'));
printf('<a href="%s" id="filter_reset_link" class="del_button">X</a>', $url);
}
}
}
开发者ID:danielbachhuber,项目名称:marcgratch.com,代码行数:26,代码来源:Clients_Admin_Table.php
示例14: render_content
public function render_content()
{
$dropdown = wp_dropdown_categories(array('name' => $this->name, 'echo' => 0, 'hide_empty' => false, 'show_option_none' => false, 'hide_if_empty' => false, 'selected' => $this->value()));
$dropdown = str_replace('<select', '<select multiple = "multiple" style = "height:95px;" ' . $this->get_link(), $dropdown);
printf('<label class="customize-control-select"><span class="customize-control-title">%s</span> %s</label>', $this->label, $dropdown);
echo '<p class="description">' . __('Hold down the Ctrl (windows) / Command (Mac) button to select multiple options.', 'catch-base') . '</p>';
}
开发者ID:RGunning,项目名称:EBItraining,代码行数:7,代码来源:catchbase-customizer-custom-controls.php
示例15: render_content
/**
* Render the control to be displayed in the Customizer.
*/
public function render_content()
{
$default_args = array('show_option_none' => ' ', 'option_none_value' => '0', 'taxonomy' => 'category');
$args = wp_parse_args($this->args, $default_args);
$args['name'] = '_customize-dropdown-taxonomies-' . $this->id;
$args['selected'] = $this->value();
$args['echo'] = false;
?>
<label>
<?php
if (!empty($this->label)) {
?>
<span class="customize-control-title"><?php
echo esc_html($this->label);
?>
</span>
<?php
}
if (!empty($this->description)) {
?>
<span class="description customize-control-description"><?php
echo $this->description;
?>
</span>
<?php
}
?>
<?php
echo str_replace('<select', '<select ' . $this->get_link(), wp_dropdown_categories($args));
?>
</label>
<?php
}
开发者ID:ernilambar,项目名称:customizer-controls,代码行数:38,代码来源:control-dropdown-taxonomies.php
示例16: restrict_manage_posts
function restrict_manage_posts()
{
global $wp_query;
if ($wp_query->query_vars['post_type'] == EM_POST_TYPE_EVENT || $wp_query->query_vars['post_type'] == 'event-recurring') {
?>
<select name="scope">
<?php
$scope = !empty($wp_query->query_vars['scope']) ? $wp_query->query_vars['scope'] : 'future';
foreach (em_get_scopes() as $key => $value) {
$selected = "";
if ($key == $scope) {
$selected = "selected='selected'";
}
echo "<option value='{$key}' {$selected}>{$value}</option> ";
}
?>
</select>
<?php
if (get_option('dbem_categories_enabled')) {
//Categories
$selected = !empty($_GET['event-categories']) ? $_GET['event-categories'] : 0;
wp_dropdown_categories(array('hide_empty' => 1, 'name' => EM_TAXONOMY_CATEGORY, 'hierarchical' => true, 'orderby' => 'name', 'id' => EM_TAXONOMY_CATEGORY, 'taxonomy' => EM_TAXONOMY_CATEGORY, 'selected' => $selected, 'show_option_all' => __('View all categories')));
}
if (!empty($_REQUEST['author'])) {
?>
<input type="hidden" name="author" value="<?php
echo esc_attr($_REQUEST['author']);
?>
" />
<?php
}
}
}
开发者ID:pyropictures,项目名称:wordpress-plugins,代码行数:33,代码来源:em-event-posts-admin.php
示例17: related_categories
function related_categories($category)
{
$category = $_REQUEST['tag_ID'];
?>
<style type="text/css">
ul.categorychecklist li {float: left; width: 33% !important;}
input[type="checkbox"], input[type="radio"] {width: auto !important;}
</style>
<tr class="form-field">
<th scope="row" valign="top"><label for="related_categories">Related Categories</label></th>
<td>
<ul id="categorychecklist" class="list:category categorychecklist form-no-clear">
<?php
$related_categories = get_option("related_categories_" . $category);
$checked = '';
$related_categories_arr = array();
if (!$related_categories) {
$checked = ' checked="checked"';
} else {
$related_categories_arr = explode(",", $related_categories);
if (in_array("0", $related_categories_arr) || $related_categories == "") {
$checked = ' checked="checked"';
}
}
?>
<li class="popular-category"><label class="selectit"><input type="checkbox" name="post_category[]" value="0"<?php
echo $checked;
?>
>All categories</label></li>
<?php
$related_categories_arr = explode(",", $related_categories);
$args = array('show_option_all' => '', 'show_option_none' => '', 'orderby' => 'name', 'order' => 'ASC', 'show_count' => 0, 'hide_empty' => 0, 'child_of' => 0, 'exclude' => '', 'echo' => 0, 'selected' => 0, 'hierarchical' => 0, 'name' => 'related_categories', 'id' => 'related_categories', 'class' => 'popular-category', 'depth' => 0, 'tab_index' => 0, 'taxonomy' => 'category', 'hide_if_empty' => false);
$select = wp_dropdown_categories($args);
$select = preg_replace("#<[/]*select[^>]*>#", "", $select);
$categories_options = explode("<option ", $select);
$final_select = "";
foreach ($categories_options as $categories_option) {
if (strlen($categories_option) < 5) {
continue;
}
$categories_option = str_replace(' class="level-0"', '', $categories_option);
$categories_option = str_replace('</option>', '</label></li>', $categories_option);
preg_match('#value="(\\d+)"#', $categories_option, $matches);
$cat_id = $matches[1];
if (in_array($cat_id, $related_categories_arr)) {
$categories_option = 'checked="checked" ' . $categories_option;
}
$final_select .= '<li class="popular-category"><label class="selectit"><input type="checkbox" name="post_category[]" ' . $categories_option;
}
echo $final_select;
?>
</ul>
</td>
</tr>
<?php
}
开发者ID:nisargadesign,项目名称:CES,代码行数:60,代码来源:functions.php
示例18: form
function form($instance)
{
$title = isset($instance['title']) ? esc_attr($instance['title']) : '';
$category = isset($instance['category']) ? esc_attr($instance['category']) : '';
?>
<p>
<label for="<?php
echo $this->get_field_id('title');
?>
">Título:</label>
<input type="text" id="<?php
echo $this->get_field_id('title');
?>
" name="<?php
echo $this->get_field_name('title');
?>
" maxlength="26" value="<?php
echo $title;
?>
" class="widefat" />
</p>
<p>
<label for="<?php
echo $this->get_field_id('category');
?>
">Categoria:</label>
<?php
wp_dropdown_categories('class=widefat&show_count=1&hierarchical=1&name=' . $this->get_field_name('category') . '&selected=' . $instance['category']);
?>
</p>
<?php
}
开发者ID:CoordCulturaDigital-Minc,项目名称:cdigital2014,代码行数:32,代码来源:widget-customPosts.php
示例19: render_content
/**
* Function to render the content on the theme customizer page
*
* @access public
* @since 1.0.0
*
* @param null
* @return void
*
*/
public function render_content()
{
$supermag_customizer_name = 'supermag_customizer_dropdown_categories_' . $this->id;
$supermag_dropdown_categories = wp_dropdown_categories(array('name' => $supermag_customizer_name, 'echo' => 0, 'show_option_none' => __('Select', 'supermag'), 'option_none_value' => '0', 'selected' => $this->value()));
$supermag_dropdown_final = str_replace('<select', '<select ' . $this->get_link(), $supermag_dropdown_categories);
printf('<label><span class="customize-control-title">%s</span> %s</label>', $this->label, $supermag_dropdown_final);
}
开发者ID:jasonralph,项目名称:jasonralph.org,代码行数:17,代码来源:custom-controls.php
示例20: widget
function widget($args, $instance)
{
extract($args, EXTR_SKIP);
$category_id = empty($instance['category_id']) ? 1 : $instance['category_id'];
$use_cat_title = empty($instance['use_cat_title']) ? 0 : $instance['use_cat_title'];
$hide_empty_cats = empty($instance['hide_empty_cats']) ? 0 : $instance['hide_empty_cats'];
$show_post_count = empty($instance['show_post_count']) ? 0 : $instance['show_post_count'];
$title_link = empty($instance['title_link']) ? 0 : $instance['title_link'];
$excluded = empty($instance['excluded']) ? '' : $instance['excluded'];
$sub_subs = empty($instance['sub_subs']) ? 0 : $instance['sub_subs'];
$dropdown = empty($instance['dropdown']) ? 0 : $instance['dropdown'];
$post_is_parent = empty($instance['post_is_parent']) ? 0 : $instance['post_is_parent'];
$dropdown_text = empty($instance['dropdown_text']) ? __('Select Sub-category', 'sub-categories-widget') : $instance['dropdown_text'];
$list_order = empty($instance['list_order']) ? 0 : $instance['list_order'];
if ($post_is_parent) {
$category = get_the_category();
$category_id = $category ? $category[0]->cat_ID : 1;
}
if ($use_cat_title) {
$title = apply_filters('widget_title', get_cat_name($category_id), $instance, $this->id_base);
} else {
$title = apply_filters('widget_title', empty($instance['title']) ? __('Sub Categories', 'sub-categories-widget') : $instance['title'], $instance, $this->id_base);
}
$parent = $sub_subs == 1 ? 'child_of' : 'parent';
$order = $list_order == 1 ? 'DESC' : 'ASC';
$no_sub_text = '<p>' . __('No sub-categories', 'sub-categories-widget') . '</p>';
$subs = wp_list_categories(array($parent => $category_id, 'hide_empty' => $hide_empty_cats, 'show_count' => $show_post_count, 'exclude' => $excluded, 'title_li' => null, 'show_option_none' => '', 'echo' => 0, 'orderby' => 'ID', 'order' => $order));
if ($post_is_parent == 0 || $post_is_parent == 1 && !empty($subs)) {
echo $before_widget;
if ($title_link) {
echo $before_title . '<a href="' . get_category_link($category_id) . '">' . $title . '</a>' . $after_title;
} else {
echo $before_title . $title . $after_title;
}
if ($dropdown == 0) {
if (!empty($subs)) {
echo '<ul>' . $subs . '</ul>';
} else {
echo $no_sub_text;
}
} else {
$subs = wp_dropdown_categories(array('id' => 'sub-cat-' . $this->number, 'show_option_none' => $dropdown_text, $parent => $category_id, 'hide_empty' => $hide_empty_cats, 'show_count' => $show_post_count, 'exclude' => $excluded, 'hide_if_empty' => true, 'echo' => false, 'orderby' => 'ID', 'order' => $order));
if (!empty($subs)) {
echo $subs;
echo '<script type="text/javascript">
/* <![CDATA[ */
var dropdown' . $this->number . ' = document.getElementById("sub-cat-' . $this->number . '");
function onSubCatChange() {
if (dropdown' . $this->number . '.options[dropdown' . $this->number . '.selectedIndex].value > 0) { location.href = "' . get_option('home') . '?cat="+dropdown' . $this->number . '.options[dropdown' . $this->number . '.selectedIndex].value; }
}
dropdown' . $this->number . '.onchange = onSubCatChange;
/* ]]> */
</script>';
} else {
echo $no_sub_text;
}
}
echo $after_widget;
}
}
开发者ID:phongvan212,项目名称:kinhte,代码行数:60,代码来源:sub-categories-widget.php
注:本文中的wp_dropdown_categories函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论