2016-09-20 42 views
0

我使用强制摘录代码自动生成摘录的内容,而无需使用多个标签或摘录编辑器对话框中的functions.php如下:的WordPress如何添加TinyMCE的格式排功能后> ID摘录过滤

function mytheme_excerpt_read_more_link($output) { 
    global $post; 
    return $output . ' <div class="more-link"> 
    <a href="' . get_permalink($post->ID) . '>Read More</a></div>'; 
    } 
add_filter('the_excerpt', 'mytheme_excerpt_read_more_link'); 

但是,我需要添加TinyMCE函数,以便如果某人在编辑器中添加斜体(例如),<em>将在摘录代码中选取。

这是我定制TinyMCE的:

add_filter('mce_buttons', 'mrw_mce_buttons_1'); 
    function mrw_mce_buttons_1($buttons) { 
    $buttons = array('styleselect', 'bold', 'italic', 
    'link', 'unlink', 'bullist', 'numlist', 'indent', 
    'outdent', 'pastetext', 'removeformat', 'charmap', 
    'undo', 'redo', 'wp_more','wp_help', ); 

return $buttons; 
} 

怎样上述过滤器添加到后> ID?我试过,但没有奏效:

function my_theme_add_tinymce_styles() { 
    global $post; 
    $post_type = get_post_type($post->ID); 
    $tinymce_style = 'mrw_mce_buttons_1'; 
    add_editor_style($tinymce_style); 
    } 
add_action('pre_get_posts', 'my_theme_add_tinymce_styles'); 

感谢 查尔斯

回答

0

这使得相同TinyMCE的设置这是在编辑器窗口进入摘录窗口:

<?php 
//adjust Excerpt box height 
function admin_excerpt() { echo "<style>"; echo "textarea#excerpt {height:300px;}"; echo "</style>"; } add_action('admin_head', 'admin_excerpt'); 


/*from http://easywebdesigntutorials.com/customizing-the-excerpts-meta-box/ 
Code to adding the TinyMCE visual editor to an excerpt is from: 
https://marcgratch.com/add-tinymce-to-excerpt/ 

Code 1. 
To me this seems like the best code of the 3 to use. */ 


function lb_editor_remove_meta_box() { 
global $post_type; 
/** 
* Check to see if the global $post_type variable exists 
* and then check to see if the current post_type supports 
* excerpts. If so, remove the default excerpt meta box 
* provided by the WordPress core. If you would like to only 
* change the excerpt meta box for certain post types replace 
* $post_type with the post_type identifier. 
*/ 
if (isset($post_type) && post_type_supports($post_type, 'excerpt')){ 
remove_meta_box('postexcerpt', $post_type, 'normal'); 
} 
} 
add_action('admin_menu', 'lb_editor_remove_meta_box'); 

function lb_editor_add_custom_meta_box() { 
global $post_type; 
/** 
* Again, check to see if the global $post_type variable 
* exists and then if the current post_type supports excerpts. 
* If so, add the new custom excerpt meta box. If you would 
* like to only change the excerpt meta box for certain post 
* types replace $post_type with the post_type identifier. 
*/ 
if (isset($post_type) && post_type_supports($post_type, 'excerpt')){ 
add_meta_box('postexcerpt', __('Excerpt'), 'lb_editor_custom_post_excerpt_meta_box', $post_type, 'normal', 'high'); 
} 
} 
add_action('add_meta_boxes', 'lb_editor_add_custom_meta_box'); 

function lb_editor_custom_post_excerpt_meta_box($post) { 

/** 
* Adjust the settings for the new wp_editor. For all 
* available settings view the wp_editor reference 
* http://codex.wordpress.org/Function_Reference/wp_editor 
*/ 
$settings = array('textarea_rows' => '12', 'quicktags' => true, 'tinymce' => true); 

/** 
* Create the new meta box editor and decode the current 
* post_excerpt value so the TinyMCE editor can display 
* the content as it is styled. 
*/ 
wp_editor(html_entity_decode(stripcslashes($post->post_excerpt)), 'excerpt', $settings); 

// The meta box description - adjust as necessary 
// echo '&lt;p&gt;&lt;em&gt;Excerpts are optional, hand-crafted, summaries of your content.&lt;/em&gt;&lt;/p&gt;'; 
} 

// add Text (HTML)