代码之家  ›  专栏  ›  技术社区  ›  Alex Osipov

Wordpress将wp_editor添加到custom_meta_box

  •  0
  • Alex Osipov  · 技术社区  · 10 年前

    有人能帮忙吗?我创建了自定义的元框,其中两个位于文本区域。 这就是我所拥有的:

    array(
            'label'=> 'Ingredients',
            'desc'  => 'List of ingrediends',
            'id'    => $prefix.'ingrediends',
            'type'  => 'textarea'
        ),
            array(
            'label'=> 'Directions',
            'desc'  => 'Directions',
            'id'    => $prefix.'directions',
            'type'  => 'textarea'
        )
    

    ==========================

    case 'textarea':
        echo '<textarea name="'.$field['id'].'" id="'.$field['id'].'" cols="60" rows="4">'.$meta.'</textarea>
            <br /><span class="description">'.$field['desc'].'</span>';
    break; 
    

    如何添加wp_editor?我尝试了:

    wp_editor( $content, 'recipe_directions', array( 'textarea_name' => 'recipe_directions', 'media_buttons' => false, 'tinymce' => array() ) );
    

    但没有运气。有人能帮忙吗。 整个想法是使常规文本区域类似于富格文本编辑器

    感谢您的帮助……任何人:)

    1 回复  |  直到 10 年前
        1
  •  0
  •   Gavin Simpson    10 年前

    迟到总比不到。。。。。

    在类init函数中(假设它是插件类)添加

    add_meta_box(
        'ingredients_box_id',
        __( 'Ingredients', $this->textdomain ),
        array($this,'ingredients_box_content'),
        'ingredients_box',
        'advanced',
        'high'
    );
    

    然后添加函数以启用wp_Editor

    function ingredients_box_content( $post )
    {
        wp_editor( $meta_biography, 'ingredients_box_text_id', array(
            'wpautop'       => true,
            'media_buttons' => false,
            'textarea_name' => 'ingredients_box_text',
            'textarea_rows' => 10,
            'teeny'         => true
        ) );
    }
    
    推荐文章