将 wp_editor 添加到用户创建的 metabox
Adding wp_editor to user created metabox
因此,我设置了一个插件,允许我的客户能够使用按钮添加元数据框,从而添加更加动态的新内容,以及额外的 titles/headings 等。这就是它的方式立即设置...
function Print_price_fileds($cnt, $p = null) {
if ($p === null){
$a = $b = $c = '';
}else{
$a = $p['n'];
$b = $p['d'];
$c = $p['p'];
}
return <<<HTML
<li>
<input type="text" name="additional_content[$cnt][d]" size="50" value="$b" placeholder="Title"/>
<textarea name="additional_content[$cnt][p]" class="wp-editor-area" style="height: 320px; width: 100%; margin-top: 37px;" autocomplete="off" placeholder="Content">$c</textarea>
<span class="remove submitdelete deletion">Remove</span>
</li>
HTML
;
}
function additional_content_boxes(){
global $post;
$data = get_post_meta($post->ID,"additional_content",true);
echo '<div>';
echo '<ul id="additional_content_items">';
$c = 0;
if (count($data) > 0){
foreach((array)$data as $p ){
if (isset($p['p']) || isset($p['d'])|| isset($p['n'])){
echo Print_price_fileds($c,$p);
$c = $c +1;
}
}
}
echo '</ul>';
?>
<span id="here"></span>
<span class="add button button-primary button-large"><?php echo __('Add Additional Content'); ?></span>
<script>
var $ =jQuery.noConflict();
$(document).ready(function() {
var count = <?php echo $c - 1; ?>; // substract 1 from $c
$(".add").click(function() {
count = count + 1;
$('#additional_content_items').append('<? echo implode('',explode("\n",Print_price_fileds('count'))); ?>'.replace(/count/g, count));
return false;
});
$(".remove").live('click', function() {
$(this).parent().remove();
});
});
</script>
<style>#additional_content_items {list-style: none; padding-bottom: 20px; border-bottom: 1px solid #ddd; margin-top: 30px; display: block;}</style>
<?php
echo '</div>';
}
这现在工作得很好,但我希望能够将 wp_editor
添加到其他元数据框,从而替换 <textarea>
。我怎样才能做到这一点?
谢谢大家。
J
因此,我采纳了 Noman 的建议并使用了 Advanced Custom Fields 插件。不知道为什么我以前没有听说过它,因为它很完美。谢谢大家!
因此,我设置了一个插件,允许我的客户能够使用按钮添加元数据框,从而添加更加动态的新内容,以及额外的 titles/headings 等。这就是它的方式立即设置...
function Print_price_fileds($cnt, $p = null) {
if ($p === null){
$a = $b = $c = '';
}else{
$a = $p['n'];
$b = $p['d'];
$c = $p['p'];
}
return <<<HTML
<li>
<input type="text" name="additional_content[$cnt][d]" size="50" value="$b" placeholder="Title"/>
<textarea name="additional_content[$cnt][p]" class="wp-editor-area" style="height: 320px; width: 100%; margin-top: 37px;" autocomplete="off" placeholder="Content">$c</textarea>
<span class="remove submitdelete deletion">Remove</span>
</li>
HTML
;
}
function additional_content_boxes(){
global $post;
$data = get_post_meta($post->ID,"additional_content",true);
echo '<div>';
echo '<ul id="additional_content_items">';
$c = 0;
if (count($data) > 0){
foreach((array)$data as $p ){
if (isset($p['p']) || isset($p['d'])|| isset($p['n'])){
echo Print_price_fileds($c,$p);
$c = $c +1;
}
}
}
echo '</ul>';
?>
<span id="here"></span>
<span class="add button button-primary button-large"><?php echo __('Add Additional Content'); ?></span>
<script>
var $ =jQuery.noConflict();
$(document).ready(function() {
var count = <?php echo $c - 1; ?>; // substract 1 from $c
$(".add").click(function() {
count = count + 1;
$('#additional_content_items').append('<? echo implode('',explode("\n",Print_price_fileds('count'))); ?>'.replace(/count/g, count));
return false;
});
$(".remove").live('click', function() {
$(this).parent().remove();
});
});
</script>
<style>#additional_content_items {list-style: none; padding-bottom: 20px; border-bottom: 1px solid #ddd; margin-top: 30px; display: block;}</style>
<?php
echo '</div>';
}
这现在工作得很好,但我希望能够将 wp_editor
添加到其他元数据框,从而替换 <textarea>
。我怎样才能做到这一点?
谢谢大家。 J
因此,我采纳了 Noman 的建议并使用了 Advanced Custom Fields 插件。不知道为什么我以前没有听说过它,因为它很完美。谢谢大家!