在wordpress里自定义了一个小工具,把网站分类目录放进一个选择下拉框里,选择想要显示的分类,可是总无法保存选定的分类,是不是在小工具里不能实现这个功能?
<p>
<label>
选择栏目:
<select style="width:100%;" id="catsel" name="catsel">
<?php echo get_category_list( $instance['catsel'] ); ?>
</select>
</label>
</p>
这是调用的函数:
function get_category_list( $cid ) {
$args = array(
'hide_empty'=> 0,
);
$catlist = '';
$categories = get_categories( $args );
if( !$categories ) return '<option vaule="0">没有栏目</option>';
foreach ( $categories as $category ){
$catlist .= '<option vaule="'. $category->term_id .'" '.selected($category->term_id,$cid).'>'. $category->name.'</option>';
}
return $catlist;
}
我没有在你的代码里看到保存的部分啊。
这个功能是可以实现的,因为已经有人做出来了。
最简单的实现办法是直接拿来用。
地址:https://wordpress.org/plugins...