wordpress文章添加多个编辑器
我们在制作一些企业网站的时候,会有一些非常多的说明的产品,比如说参数拉、图片啦、说明拉等等,需要分开来表述,这样我们的产品就会比较清晰,如下图联想官网的模式:
可以点击进入感受一下
那么,如果我们想要添加这样的标签转换的正文内容应该如何做到呢?
给wordpress添加多个编辑器
给wordpress添加多个编辑器,即可实现这样的效果,下图就是我们做出的实验,在撰写文章时,在底部添加了多个编辑器:
这样就能是实现多个内容输出,而且可以编辑文章和图片、链接等和正文一样的内容输出,美观方便。
如何实现wordpress多个编辑器
<?php echo get_post_meta($post->ID, 'content_1',true);?> 模版输出 function.php添加 $new_meta_boxes4 = array( "content_1" => array( "name" => "content_1", "std" => "", "title" => "输入框1"),//这里注册一下输入框,如果你要多个 就把这个array在复制到下面的括号内,参数要改下,具体参考下面有一个注释过的 // "content_2" => array( // "name" => "content_2", // "std" => "", // "title" => "输入框2"),如果你想要多个,依次类推复制即可 ); function new_meta_boxes4() { global $post, $new_meta_boxes4; $meta_box_value = get_post_meta($post->ID,"content_1", true);//注册好了之后 赋值给文章的“自定义栏目”,post_meta就是文章的自定义栏目,这里的数据实际上是存在自定义栏目中的,下面是对应的第二个编辑器的例子: //$meta_box_value2 = get_post_meta($post->ID,"content_2", true); echo' <input type="hidden" name="content_1_noncename" id="content_1_noncename" value="'.wp_create_nonce( plugin_basename(__FILE__) ).'" />';//这个是隐藏的表单,用来提交的,下面是标题和编辑框的输出 echo'<h4>自定义编辑框1</h4>'; echo wp_editor(get_post_meta($post->ID, "content_1", true), "content_1", $settings = array('wpautop' => true,) );// wp_editor这个函数就是用来吧WordPress的编辑器输出出来的 //以上就是一个编辑框的输出,想要输出多个复制到下面,注意复制之后content_1都改为最上面注册时候的名字 下面是例子: // echo' // <input type="hidden" name="content_2_noncename" id="content_2_noncename" value="'.wp_create_nonce( plugin_basename(__FILE__) ).'" />'; // // // echo'<h4>自定义编辑框2</h4>'; // echo wp_editor(get_post_meta($post->ID, "content_2", true), "content_2", $settings = array('wpautop' => true,) ); } function create_meta_box4() { global $theme_name; if ( function_exists('add_meta_box') ) { add_meta_box( 'new-meta-boxes4', '多编辑器输出', 'new_meta_boxes4', 'post', 'normal', 'high' );//这里是显示在文章编辑中的标题 //注意看后面的post,这个是显示在文章里面的,如果你想要页面也显示,复制一下这一行,吧post改为page就行了,下面的都不用改了 } } function save_postdata4( $post_id ) { global $post, $new_meta_boxes4; foreach($new_meta_boxes4 as $meta_box) { if ( !wp_verify_nonce( $_POST[$meta_box['name'].'_noncename'], plugin_basename(__FILE__) )) { return $post_id; } if ( 'page' == $_POST['post_type'] ) { if ( !current_user_can( 'edit_page', $post_id )) return $post_id; } else { if ( !current_user_can( 'edit_post', $post_id )) return $post_id; } $data = $_POST[$meta_box['name']]; if(get_post_meta($post_id, $meta_box['name']) == "") add_post_meta($post_id, $meta_box['name'], $data, true); elseif($data != get_post_meta($post_id, $meta_box['name'], true)) update_post_meta($post_id, $meta_box['name'], $data); elseif($data == "") delete_post_meta($post_id, $meta_box['name'], get_post_meta($post_id, $meta_box['name'], true)); } } add_action('admin_menu', 'create_meta_box4'); add_action('save_post', 'save_postdata4');