Wordpress 自定义帖子类型中的多个编辑器(TinyMCE)
我有一个定制的产品后类型。我有两个TinyMCE编辑器(标准编辑器和一个摘要字段编辑器)在仪表板中正确加载。从仪表板的角度来看,一切正常。添加、更新。等等 然而,在网站上,输出失去了换行符(段落标记)。以下是一个例子: 我正在为此使用wp_编辑器函数。(http://codex.wordpress.org/Function_Reference/wp_editor) 这是我的密码:Wordpress 自定义帖子类型中的多个编辑器(TinyMCE),wordpress,tinymce,custom-post-type,Wordpress,Tinymce,Custom Post Type,我有一个定制的产品后类型。我有两个TinyMCE编辑器(标准编辑器和一个摘要字段编辑器)在仪表板中正确加载。从仪表板的角度来看,一切正常。添加、更新。等等 然而,在网站上,输出失去了换行符(段落标记)。以下是一个例子: 我正在为此使用wp_编辑器函数。(http://codex.wordpress.org/Function_Reference/wp_editor) 这是我的密码: <?php function keg_product_fields (){ global $post; $c
<?php
function keg_product_fields (){
global $post;
$custom = get_post_custom($post->ID);
$keg_product_price = $custom["keg_product_price"][0];
$keg_product_link = $custom["keg_product_link"][0];
$keg_product_type = $custom["keg_product_type"][0];
$keg_product_featured = $custom["keg_product_featured"][0];
$keg_product_summary = $custom["keg_product_summary"][0];
$editor_id = "kegprodsummary"
?>
<p>
<label>Summary:</label><br />
<?php wp_editor( $keg_product_summary, $editor_id, $settings = array('textarea_name' => 'keg_product_summary') ); ?>
</p>
<p>
<label>Price:</label><br />
<input size="10" name="keg_product_price" value="<?php echo $keg_product_price; ?>" />
</p>
<p>
<label>Type:</label><br />
<select name="keg_product_type">
<option value="<?php echo $keg_product_type; ?>" selected="selected"><?php echo $keg_product_type; ?></option>
<option value="Book">Book</option>
<option value="CD">CD</option>
<option value="Downloadable">Downloadable</option>
<option value="Multimedia">Multimedia</option>
<option value="Virtual">Virtual</option>
</select>
</p>
<p>
<label>Link:</label><br />
<input size="65" maxlength="200" name="keg_product_link" value="<?php echo $keg_product_link; ?>" />
</p>
<p>
<input type="checkbox" name="keg_product_featured" value="Yes" <?php if (!(strcmp("$keg_product_featured","Yes"))) {echo "checked=\"checked\"";} ?>/>
<label>Featured Product</label>
</p>
<?php
}
function add_keg_product_box (){
add_meta_box(
"keg_product_info",
"Product Details",
"keg_product_fields",
"keg_products"
);
}
function save_keg_product_attributes ( $post_id )
{
if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) {
return $post_id;
}
global $post;
update_post_meta($post->ID, "keg_product_price", $_POST["keg_product_price"]);
update_post_meta($post->ID, "keg_product_link", $_POST["keg_product_link"]);
update_post_meta($post->ID, "keg_product_type", $_POST["keg_product_type"]);
update_post_meta($post->ID, "keg_product_featured", $_POST["keg_product_featured"]);
update_post_meta($post->ID, "keg_product_summary", $_POST["keg_product_summary"]);
}
add_action ('admin_init', 'add_keg_product_box' );
add_action ('save_post', 'save_keg_product_attributes');
add_action ('publish_post', 'save_keg_product_attributes');
?>
总结:
价格:
保存内容或显示内容时,请尝试使用wpcautop()
(为了提高性能,我建议您在保存时使用它)。
此函数根据换行符在整个文本中添加段落。您必须在要显示摘要的页面中使用“应用过滤器”功能应用输出过滤器
例如:
<?php
$summary = get_post_meta(...);
echo apply_filters('the_content', $summary);
?>
我在该页面上看不到任何tinymce编辑器。很抱歉,该页面就是段落标签被剥离的一个例子。它正在保存粗体等。如果标记被剥离,您可能不需要调整有效元素和有效子元素的默认设置:将其添加到自定义post code之前的函数文件-wp_tiny_mce(false,array('remove_linebreaks'=>'false','convert_newlines_to_brs'=>'true')代码>