WP_Widget_Tag_Cloud{}

用于实现Tag云小部件的核心类。

描述

另请参见

方法

姓名描述
WP_Widget_Tag_Cloud::__构造设置新的Tag Cloud小部件实例。
WP_Widget_Tag_Cloud::_get_current_taxonomy(WP_Wigget_Tag_Cloud)检索当前标记云小部件实例的分类。
WP_Widget_Tag_Cloud::表单输出标记云小部件设置表单。
WP_Widget_Tag_Cloud::更新处理当前Tag Cloud小部件实例的更新设置。
WP_Widget_Tag_Cloud::小部件输出当前标记云小部件实例的内容。

来源

类WP_Widget_Tag_Cloud扩展了WP_Widlet{/***设置新的Tag Cloud小部件实例。**@自2.8.0起*/公共函数__construct(){$widget_ops=数组(‘description’=>__(‘最常用的标签云’),“customize_selective_refresh”=>true,“show_instance_in_rest”=>true,);父级::__construct('tag_cloud',__('tag cloud'),$widget_ops);}/***输出当前标记云小部件实例的内容。**@自2.8.0起**@param array$args显示参数,包括“before_title”、“after_title”、,*'before_widget'和'after_widget]。*当前Tag Cloud小部件实例的@param array$instance设置。*/公共功能小部件($args,$instance){$current_taxonomy=$this->_get_current_taxonom($instance);if(!空($instance['title']){$title=$instance[“标题”];}其他{if('post_tag'===$current_taxonomy){$title=__(“标签”);}其他{$tax=get_taxonomy($current_taxonom);$title=$tax->labels->name;}}$default_title=$title;$show_count=!空($instance['count']);$tag_cloud=wp_tag_cloud(/***过滤“标记云”小部件中使用的分类。**@自2.8.0起*@since 3.0.0添加了分类下拉列表。*@since 4.9.0添加了`$instance`参数。**@参见wp_tag_cloud()**@param array$args用于标记云小部件的参数。*@param array$instance当前小部件的设置数组。*/应用筛选器(“widget_tag_cloud_args”,阵列(“taxonomy”=>$current_taxonomy,“echo”=>错误,“show_count”=>$show_cont,),$实例));if(空($tag_cloud)){回报;}/**该过滤器记录在wp-includes/widgets/class-wp-widget-pages.php中*/$title=应用过滤器('widget_title',$title,$instance,$this->id_base);echo$args[“小部件之前”];if($title){echo$args[“标题之前”]$标题$args['after_title'];}$format=current_theme_supports('html5','navigation-widgets')?'html5':'xhtml';/**该过滤器记录在wp-includes/widgets/class-wp-nav-menu-widget.php中*/$format=apply_filters('navigation_widgets_format',$format);if('html5'===$format){//标题可能会被过滤:去掉HTML并确保aria-label永远不为空。$title=修剪(strip_tags($title));$aria_label=$title$标题:$default_title;echo'<nav aria-label=“'.esc_attr($aria_label).'”>';}echo'<div class=“tagcloud”>';echo$tag_cloud;echo“</div>\n”;if('html5'===$format){echo“</nav>”;}echo$args['after_widget'];}/***处理当前标记云小部件实例的更新设置。**@自2.8.0起**@param array$new_instance用户通过输入此实例的新设置*WP_Widget::form()。*@param array$old_instance此实例的旧设置。*@return array Settings保存,bool false取消保存。*/公共函数更新($new_instance,$old_instance){$instance=数组();$instance['title']=清理文本字段($new_instance['标题']);$instance['count']=!空($new_instance['count'])?1 : 0;$instance['taxonomy']=条带斜线($new_instance['taxonomy']);return$instance;}/***输出标记云小部件设置窗体。**@自2.8.0起**@param array$instance当前设置。*/公共函数窗体($instance){$title=!空($instance['title'])$实例[“标题”]:“”;$count=isset($instance['count'])?(bool)$instance['count']:false;?><p><label for=“<?php echo$this->get_field_id('title');?>”><?php_e('标题:');?></标签><input type=“text”class=“widefat”id=“<?php echo$this->get_field_id('title');?>”name=“<?hp echo$this->get_field_name('titel');”>“value=”<?php-echo esc_attr($title);?>>“/></p><?php(电话)$taxonomies=get_taxonomies(数组('show_tagcloud'=>true),'object');$current_taxonomy=$this->_get_current_taxonom($instance);开关(计数($taxonomies)){//找不到支持分类法的标记云,显示错误消息。案例0:?><input type=“hidden”id=“<?php echo$this->get_field_id('taxonomic');?>”name=“<?hp echo$this->get_field_name('taxonumic')?>”value=“”/><p><?php_e('由于没有支持标记云小部件的分类法,因此不会显示标记云。');?></p><?php(电话)断裂;//只找到支持分类法的单个标记云,无需显示select。案例1:$keys=数组键($taxonomies);$taxonomy=重置($keys);?><input type=“hidden”id=“<?php echo$this->get_field_id('分类法');?>”name=“<?php echo$this->get_field_name('taxonomic');”value=“<?php echo esc_attr($taxonymic')?>”/><?php(电话)断裂;//找到多个支持分类法的标记云,显示一个选择。违约:?><p><label for=“<?php echo$this->get_field_id('分类法');?>”><?php_e('分类:');?></标签><select class=“widefat”id=“<?php echo$this->get_field_id('分类法');?>”name=“<?php-foreach($taxonomies作为$taxon=>$tax):?><option value=“<?php echo esc_attr($taxonomy);?>”<?选择的php($taxonomy,$current_taxonomy);?>><?php-echo-eschtml($tax->labels->name);?></选项><?php endforeach;?></选择></p><?php(电话)}if(计数($taxonomies)>0){?><p><input type=“checkbox”class=“checkbox”id=“<?php echo$this->get_field_id('count');?>”name=“<?php echo$this->get_field_name('count');?>”<?php已检查($count,true);?>/><label for=“<?php echo$this->get_field_id('count');?>”><?php_e('显示标记计数');?></标签></p><?php(电话)}}/***检索当前Tag云小部件实例的分类法。**@自4.4.0起**@param array$instance当前设置。*@return string当前分类法的名称(如果已设置),否则为“post_tag”。*/公共函数getcurrenttaxonomy($instance){if(!empty($instance['taxanomy'])&&taxonomy_exists($instance['taxonyme'])){return$instance['axonomy'];}return'post_tag';}}

变更日志

版本描述
2.8.0介绍。

用户贡献的笔记

你必须登录在能够发表注释或反馈之前。