puis-je ajouter un format personnalisé à l'option de format dans le panneau de texte?
-
-
WP3et TinyMCE sonttellementfoirés dans cet aspect.Jene peuxpas croire qu'ilne soitpaspossible d'ajouter ou depersonnaliserfacilement lesfoutusformats comme dans CKEditor.WP3 and TinyMCE is so messed up in this aspect. I cannot believe that it's not possible to easily add or customize the damn formats like it is in CKEditor.
- 2
- 2010-12-10
- cherouvim
-
Je suis d'accord,c'est une douleurtotale.I agree, it's a total pain.
- 1
- 2010-12-11
- Mild Fuzz
-
2 réponses
- votes
-
- 2010-11-10
L'éditeur TinyMCE "classique" comporte deux listes déroulantes:
formatselect
pour les styles deparagraphe etstyleselect
pour les styles de caractères - quipeut également contenir des styles deparagraphe,pour le rendreplus déroutant. La configuration dans WordPresspar défautn'affiche que lemenu déroulant format . Si vous appliquez unefeuille de stylepersonnalisée à l'éditeur,TinyMCEpeut l'utiliserpour récupérer lesnoms de classeet les ajouter à la liste déroulante style -mais celan'apasfonctionné à chaquefoispourmoi.Depuis la version 3.0,vouspouvez appeler
add_editor_style()
dans votrefunctions.php
pour ajouter unefeuille de style à l'éditeur. Par défaut,c'esteditor-style.css
dans votre répertoire dethèmes. Avant la version 3.0,vous devez vous connecter aufiltremce_css
pour ajouter l'URL à lafeuille de style de votre éditeur. Cela aboutira à lacontent_css
valeur de configuration TinyMCE .Pour ajouter la liste déroulante style ,l'option
styleselect
doit apparaître dans l'un destableaux de configuration de labarre deboutons (theme_advanced_buttons[1-4]
dans TinyMCE,filtréparmce_buttons_[1-4]
dans WordPress ). La liste desformats deblocest contrôléepar l'optiontheme_advanced_blockformats
de TinyMCE ,que vouspouvez ajouter autableau de contrôle dans lefiltretiny_mce_before_init
. Si vous souhaitezpersonnaliser lesnoms de la liste déroulante style (pas seulement vosnoms de classe CSS),consultez l'optiontheme_advanced_styles
. Vouspouvez également utiliser l'optionstyle_formats
plus avancée qui vousen donneplusflexibilitépour définir les styles.Le code PHP correspondant avectous les hookset la configurationpar défaut setrouve dans
wp-admin/includes/post.php
,dans lafonctionwp_tiny_mce()
. Dans l'ensemble,votre configurationpourrait ressembler à ceci:add_action( 'after_setup_theme', 'wpse3882_after_setup_theme' ); function wpse3882_after_setup_theme() { add_editor_style(); } add_filter('mce_buttons_2', 'wpse3882_mce_buttons_2'); function wpse3882_mce_buttons_2($buttons) { array_unshift($buttons, 'styleselect'); return $buttons; } add_filter('tiny_mce_before_init', 'wpse3882_tiny_mce_before_init'); function wpse3882_tiny_mce_before_init($settings) { $settings['theme_advanced_blockformats'] = 'p,h1,h2,h3,h4'; // From http://tinymce.moxiecode.com/examples/example_24.php $style_formats = array( array('title' => 'Bold text', 'inline' => 'b'), array('title' => 'Red text', 'inline' => 'span', 'styles' => array('color' => '#ff0000')), array('title' => 'Red header', 'block' => 'h1', 'styles' => array('color' => '#ff0000')), array('title' => 'Example 1', 'inline' => 'span', 'classes' => 'example1'), array('title' => 'Example 2', 'inline' => 'span', 'classes' => 'example2'), array('title' => 'Table styles'), array('title' => 'Table row 1', 'selector' => 'tr', 'classes' => 'tablerow1'), ); // Before 3.1 you needed a special trick to send this array to the configuration. // See this post history for previous versions. $settings['style_formats'] = json_encode( $style_formats ); return $settings; }
The "classic" TinyMCE editor has two dropdowns:
formatselect
for paragraph styles andstyleselect
for character styles - which can also contain paragraph styles, to make it more confusing. The configuration in WordPress by default only shows the format dropdown. If you apply a custom stylesheet to the editor, TinyMCE can use it to pick up the classnames and add them to the style dropdown - but this did not work every time for me.Since 3.0 you can call
add_editor_style()
in yourfunctions.php
to add a stylesheet to the editor. By default it'seditor-style.css
in your theme directory. Before 3.0 you have to hook into themce_css
filter to add the URL to your editor stylesheet. This will end up in thecontent_css
TinyMCE configuration value.To add the style dropdown, the
styleselect
option must appear in one of the button bar configuration arrays (theme_advanced_buttons[1-4]
in TinyMCE, filtered bymce_buttons_[1-4]
in WordPress). The list of block formats is controlled by thetheme_advanced_blockformats
option of TinyMCE, which you can add to the control array in thetiny_mce_before_init
filter. If you want to customize the names of the style dropdown (not just your CSS class names), look at thetheme_advanced_styles
option. You can also use the more advancedstyle_formats
option which gives you more flexibility to define the styles.The relevant PHP code with all the hooks and default configuration is in
wp-admin/includes/post.php
, in functionwp_tiny_mce()
. All together, your setup could look like this:add_action( 'after_setup_theme', 'wpse3882_after_setup_theme' ); function wpse3882_after_setup_theme() { add_editor_style(); } add_filter('mce_buttons_2', 'wpse3882_mce_buttons_2'); function wpse3882_mce_buttons_2($buttons) { array_unshift($buttons, 'styleselect'); return $buttons; } add_filter('tiny_mce_before_init', 'wpse3882_tiny_mce_before_init'); function wpse3882_tiny_mce_before_init($settings) { $settings['theme_advanced_blockformats'] = 'p,h1,h2,h3,h4'; // From http://tinymce.moxiecode.com/examples/example_24.php $style_formats = array( array('title' => 'Bold text', 'inline' => 'b'), array('title' => 'Red text', 'inline' => 'span', 'styles' => array('color' => '#ff0000')), array('title' => 'Red header', 'block' => 'h1', 'styles' => array('color' => '#ff0000')), array('title' => 'Example 1', 'inline' => 'span', 'classes' => 'example1'), array('title' => 'Example 2', 'inline' => 'span', 'classes' => 'example2'), array('title' => 'Table styles'), array('title' => 'Table row 1', 'selector' => 'tr', 'classes' => 'tablerow1'), ); // Before 3.1 you needed a special trick to send this array to the configuration. // See this post history for previous versions. $settings['style_formats'] = json_encode( $style_formats ); return $settings; }
-
y a-t-il unformat spécial que le .css devraitprendreen utilisant add_editor_style?rienne semble arriveris there a special format the .css should take using add_editor_style? nothing seems to happen
- 0
- 2010-11-10
- Mild Fuzz
-
Toujourspas dejoiepour savoir comment ajouter des classes auformatpulldown autre que celuipar défaut.Still no joy in working out how to add classes to the format pulldown other than the default.
- 0
- 2010-11-11
- Mild Fuzz
-
@Mild Fuzz: Ma réponseprécédente étaittrompeuse car WordPressn'affiche qu'un seul des deuxmenus déroulantsnécessaires.J'aimis àjourma réponse avec unmoyen d'ajouter la deuxième liste déroulanteet comment la contrôler.@Mild Fuzz: My earlier answer was misleading because WordPress shows only one of the two needed dropdowns. I updated my answer with a way to add the second dropdown and how to control it.
- 1
- 2010-11-11
- Jan Fabry
-
votrejambefin !!Jene saispas ce quefait le 'style_formats',mais le 'theme_advanced_styles'faitexactement ce dontj'aibesoin !!you leg end!! not sure what the 'style_formats' is doing, but the 'theme_advanced_styles' does exactly what I need!!
- 0
- 2010-11-11
- Mild Fuzz
-
vraimentessayer defaireen sorte que ce deuxièmeblocprenneeffet,caril semble que ce seraitextrêmement utile.Leproblèmeest que $ settings ['style_formats']estnul avant de le définir,doncje nepeuxpas comparer lesformats avec quoi que ce soit.really trying to get that second block taking an effect, as it seems like it would be immensely useful. Trouble is $settings['style_formats'] is null before we set it, so I can't compare formats with anything.
- 0
- 2010-11-11
- Mild Fuzz
-
@Mild Fuzz: Lesparamètres des différents éléments `style_formats` sontexpliqués dans lapage wiki associée [`formats`] (http://wiki.moxiecode.com/index.php/TinyMCE:Configuration/formats).@Mild Fuzz: The parameters to the different `style_formats` items are explained in the related [`formats`](http://wiki.moxiecode.com/index.php/TinyMCE:Configuration/formats) wiki page.
- 1
- 2010-11-11
- Jan Fabry
-
celamontretout dans JS,unpeu confus sur lafaçon de convertir celaen PHP quifonctionne.J'aiessayé '$ settings [' style_formats '].="Custom_format: {block:' h1 ',attributes: {title: \" Header \ "},styles: {color: red}}";'mais çatue complètementtinyMCEthat shows it all in JS, bit confused about how to convert that to PHP that works. Tried '$settings['style_formats'] .= "custom_format : {block : 'h1', attributes : {title : \"Header\"}, styles : {color : red}}";' but it kills tinyMCE completely
- 0
- 2010-11-11
- Mild Fuzz
-
@Mild Fuzz: Jepensais que WordPress appliquerait `json_encode ()` à la configuration,maisilne fait que l'imprimer.J'aimodifiéma réponsepourinclure une "injection JS"pourpasser une configuration detableau à TinyMCE.Pasgaranti defonctionner.@Mild Fuzz: I thought WordPress would apply `json_encode()` to the config, but it just prints it out. I modified my answer to include some "JS-injection" to pass an array config to TinyMCE. Not guaranteed to work.
- 0
- 2010-11-11
- Jan Fabry
-
neproduitplus d'erreurs,maisn'a aucuneffet!no longr produces errors, but has no effect!
- 1
- 2010-11-12
- Mild Fuzz
-
L'exemple de codefonctionne-t-ilet a-t-il résolu votre question?Notez que vous avez unefaute defrappe à lafin de la ligne "Styles detableau",ilfaut a)et non un}Does the sample code work and did it solve your question? Note that you have a typo at the end of line "Table styles", it needs a ) and not a }
- 0
- 2010-12-10
- cherouvim
-
json_encodegénère "etnon" donc lejavascript casse. Vous devezfaire str_replace ('"'," '",json_encode ($ style_formats))json_encode generates " and not ' so the javascript breaks. You need to do str_replace('"', "'", json_encode($style_formats))
- 1
- 2010-12-10
- cherouvim
-
Comment renommer lebouton déroulant de Formats?How do you rename the dropdown button from Formats?
- 0
- 2016-08-17
- raison
-
@raison: Il vautmieuxposer cela dans une question distincte.@raison: Best to ask that in a separate question.
- 0
- 2016-08-17
- Jan Fabry
-
- 2016-02-25
Commeici Liste déroulante duformat TinyMCEnonaffichage des aperçus de styleplus longs
Kara avait raison,vous devez annuler les stylespar défautpour voir lesnouveaux styles ...
unset($init['preview_styles']); return $settings;
As per here TinyMCE format dropdown no longer showing style previews
Kara had it right, you need to unset the default styles to see the new styles...
unset($init['preview_styles']); return $settings;
-
Veuillez ajouterplus de détails,c'estparexemplepas clair ce que `$ settings`esticiMerciPlease add some more detail, it's e.g. not clear what `$settings` is here. Thanks
- 0
- 2016-02-25
- birgire
Dans l'éditeur detexte,où vouspouvez définir desen-têteset d'autresparamètres,est-ilpossible d'ajouter vospropres styles à utiliserpar les clients?etmême supprimer lesinutiles?