我没有找到更好的办法,后来想了另一个办法:
由于WPML 是可以翻译widget title 的,所以我新建一个 blogFoll 的widget,可以填写标题,选择想要显示的分类。
直接粘贴到主题文件的functon.php 里即可。
if (!class_exists('LinksList_Widget')) : class LinksList_Widget extends WP_Widget { const LANG = 'yaocms'; function __construct() { $widget_ops = array( 'classname' => strtolower(get_class($this)) ); $control_ops = array('id_base' => strtolower(get_class($this))); $this->WP_Widget(strtolower(get_class($this)), __('Links List Widget', self::LANG), $widget_ops, $control_ops); } function widget($args, $instance) { extract($args); /* User-selected settings. */ $title = apply_filters('widget_title', empty($instance['title']) ? 'Links List' : $instance['title'] ); $link_category = ( isset($instance['link_category']) && $instance['link_category'] > 0 ) ? $instance['link_category'] : "0"; echo $before_widget; if ($title) echo $before_title . $title . $after_title; $args = array( 'categorize' => false, 'taxonomy' => 'link_category', 'category' => $link_category, 'title_before' => '<h2 style="display:none;">', 'title_after' => '</h2>', 'category_before' => '', 'category_after' => '' ); ?> <div class="recent-news recent-news-slider"> <?php wp_list_bookmarks( $args ); ?> </div> <?php echo $after_widget; } function update($new_instance, $old_instance) { $instance = $old_instance; $instance['title'] = strip_tags($new_instance['title']); $instance['link_category'] = $new_instance['link_category']; return $instance; } function form($instance) { /* Impostazioni di default del widget */ $defaults = array( 'title' => __('Links List', self::LANG), 'link_category' => 0 ); $instance = wp_parse_args((array) $instance, $defaults); ?> <p> <?php _e('Title', self::LANG) ?>: <input type="text" name="<?php echo $this->get_field_name('title'); ?>" value="<?php echo $instance['title']; ?>" class="widefat" /> </p> <p> <label for="<?php echo $this->get_field_id('items'); ?>"><?php _e('Category', self::LANG) ?>: <?php wp_dropdown_categories(array( 'show_option_all' => __('Select one', self::LANG), 'taxonomy' => 'link_category', 'name' => $this->get_field_name('link_category'), 'selected' => $instance['link_category'])); ?> </label> </p> <?php } } add_action('widgets_init', create_function('', 'return register_widget("LinksList_Widget");')); endif;