php 小工具自定义标签小部件标签云自定义标签云
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 小工具自定义标签小部件标签云自定义标签云相关的知识,希望对你有一定的参考价值。
class WP_Widget_Tag_Cloud_Custom extends WP_Widget {
function __construct() {
$widget_ops = array( 'description' => __( "Your most used tags in cloud format") );
parent::__construct('tag_cloud_custom', __('Tag Cloud Custom'), $widget_ops);
}
function widget( $args, $instance ) {
extract($args);
$current_taxonomy = 'post_tag';
if ( !empty($instance['title']) ) {
$title = $instance['title'];
} else {
if ( 'post_tag' == $current_taxonomy ) {
$title = __('Tags');
} else {
$tax = get_taxonomy($current_taxonomy);
$title = $tax->labels->name;
}
}
if(!empty($instance['tagsselected'])) {
$tagsselected = $instance['tagsselected'];
} else {
$tagsselected = 0;
}
$title = apply_filters('widget_title', $title, $instance, $this->id_base);
echo $before_widget;
if ( $title )
echo $before_title . $title . $after_title;
echo '<div class="tagcloud">';
if(empty($tagsselected))
{
wp_tag_cloud( apply_filters('widget_tag_cloud_args', array('taxonomy' => $current_taxonomy) ) );
}
else
{
$tagsids = implode(',',$tagsselected);
$tags = get_tags(array('include' => $tagsids));
foreach ( $tags as $tag )
{
$tag_link = get_tag_link( $tag->term_id );
echo '<a href="'.$tag_link.'" rel="tag">'.$tag->name.'</a> ';
}
}
echo "</div>\n";
echo $after_widget;
}
function update( $new_instance, $old_instance ) {
$instance['title'] = strip_tags(stripslashes($new_instance['title']));
$instance['tagsselected'] = $new_instance['tagsselected'];
return $instance;
}
function form( $instance ) {
?>
<p>
<label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:') ?></label>
<input type="text" class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" value="<?php if (isset ( $instance['title'])) {echo esc_attr( $instance['title'] );} ?>" />
</p>
<p>
<label for="<?php echo $this->get_field_id('tagsselected'); ?>"><?php _e('Select Tags:') ?></label>
<select class="widefat" multiple size="10" id="<?php echo $this->get_field_id('tagsselected'); ?>" name="<?php echo $this->get_field_name('tagsselected'); ?>[]">
<?php
$tags = get_tags();
foreach ( $tags as $tag )
{
$tag_link = get_tag_link( $tag->term_id );
$selected = '';
if(in_array($tag->term_id, $instance['tagsselected']))
{
$selected = 'selected="selected"';
}
echo '<option name="'.$tag->name.'" '.$selected.' value="'.$tag->term_id.'">'.$tag->name.'</option>';
}
?>
</select>
</p>
<?php
}
}
add_action('widgets_init', create_function('', 'return register_widget("WP_Widget_Tag_Cloud_Custom");'));
以上是关于php 小工具自定义标签小部件标签云自定义标签云的主要内容,如果未能解决你的问题,请参考以下文章