下拉列表中的自定义TinyMCE编辑器格式

时间:2017-03-23 作者:public9nf

我在wordpress编辑器中使用自定义TinyMCE格式。实际上,我只使用了我在函数中创建的两种格式。php:

/* TINY MCE FORMATE */
function my_mce_before_init_insert_formats( $init_array ) {  
    $style_formats = array(  
        array(  
            \'title\' => \'Button\',  
            \'selector\' => \'a\',  
            \'classes\' => \'btn\'             
        ),          
        array(  
            \'title\' => \'Download\',  
            \'selector\' => \'a\',  
            \'classes\' => \'download\'             
        ),          
    ); 

    $init_array[\'style_formats\'] = json_encode( $style_formats );  

    return $init_array;  

} 

add_filter( \'tiny_mce_before_init\', \'my_mce_before_init_insert_formats\' );
这很好用,我可以在“格式”选项卡中选择它们:enter image description here

但现在我需要更多的格式,我想在一个名为“链接”的悬停菜单中对格式进行分组。标准tinymce在悬停菜单中对标题、内联、块和对齐进行分组:enter image description here

如何将自定义格式分组?

1 个回复
SO网友:kshaner

您可以使用项目键对样式进行分组-您也可以嵌套多次!

/* TINY MCE FORMATE */
function my_mce_before_init_insert_formats( $init_array ) {  
    $style_formats = array(  
        array(  
            \'title\' => \'Buttons\',
            \'items\' => array(
                array(
                    \'title\' => \'Green\',
                    \'selector\' => \'a\',
                    \'classes\' => \'btn--green\'
                )
                array(
                    \'title\' => \'Blue Button\',
                    \'selector\' => \'a\',
                    \'classes\' => \'btn--blue\'
                )
            ),
        ),          
        array(  
            \'title\' => \'Download\',
            \'items\' => array(
                array(
                    \'title\' => \'Style 1\',
                    \'selector\' => \'a\',  
                    \'classes\' => \'download-style-1\'
                ),
                array(
                    \'title\' => \'Style 2\',
                    \'selector\' => \'a\',  
                    \'classes\' => \'download-style-2\'
                )
            )
        )
    ); 

    $init_array[\'style_formats\'] = json_encode( $style_formats );  

    return $init_array;  
} 

add_filter( \'tiny_mce_before_init\', \'my_mce_before_init_insert_formats\' );