将此代码传递给tinyMCE 4中的wordpress默认帖子中的类别。已经我已经正确完成了。
function list_categories( $cat_id, &$output = array() )
{
$categories = get_categories( 'hide_empty=0&orderby=name&order=ASC& parent=' . $cat_id );
foreach( $categories as $cat ) {
$output[] = array( 'text' => $cat->name, 'value' => $cat->term_id );
list_categories( $cat->term_id, $output );
}
return $output;
}
$list = list_categories(0); // to get an array of categories
p_localize_script( 'some_handle', 'mce_options', array( 'categories' => json_encode( list_categories(0) ) ) );
add_action( 'admin_enqueue_scripts', 'mce_admin_scripts' );
function mce_admin_scripts( $hook ) {
if ( $hook == 'post.php' || $hook == 'post-new.php' ) {
add_action( "admin_head-$hook", 'mce_admin_head' );
}
}
function mce_admin_head() {
echo '<script type="text/javascript">var mce_options=' . json_encode( array( 'categories' => list_categories(0) ) ) . '; </script>';
}
{
type: 'listbox',
name: 'sdscategory',
label: 'Category',
'values': mce_options.categories
}
但我的问题是我需要从tineMCE 4中的自定义帖子传递自定义类别。比如我创建自定义帖子类型&#39; bxcarousel&#39; &amp;自定义类别&#39; bx_carousel_cata&#39; 。我不是php的专家所以请帮帮我