• Resolved danielwiener

    (@danielwiener)


    I am making a site that is more CMS than blog. I have created 6 meta boxes to the Edit Post page. I want each meta box to use quicktags. Everything is working with the custom meta boxes AND the quicktags appear above every meta box, EXCEPT if you use the quicktags in one meta box the html is always written in the last meta box never where you want it. I have been working on this for a while and have found no tutorials or advice. I have also studied quicktags.js quite thoroughly and I know there is a way to implement quicktags in multiple instances but I cannot figure out how to do it. Any help would be much appreciated. My code is below:

    function new_meta_boxes() {
    global $post, $new_meta_boxes;
    
    $tab_index_count = 30;
    
    foreach($new_meta_boxes as $meta_box) {
    $meta_box_value = get_post_meta($post->ID, $meta_box['name'].'_value', true);
    
    $textarea_name = $meta_box['name'];
    $textarea_id = str_replace('_', '' , $textarea_name);
    
    if($meta_box_value == "")
    $meta_box_value = $meta_box['std'];
    
    echo'<input type="hidden" name="'.$meta_box['name'].'_noncename" id="'.$meta_box['name'].'_noncename" value="'.wp_create_nonce( basename(__FILE__) ).'" />';
    
    echo '<h3>'. $meta_box['title'] .' - '. $meta_box['description'] .'</h3>';
    /* var_dump($new_meta_boxes); */
    echo '<div class="">';
    echo '	<script type="text/javascript">edToolbar("' . $textarea_id . '")</script>';
    echo '<textarea rows="6" class="form-input-tip" cols="80" name="'.$meta_box['name'].'_value" tabindex="' . $tab_index_count . '" id="' . $textarea_id . '" style="width: 97%">';
    echo wpautop($meta_box_value);
    echo '</textarea> <script type="text/javascript">';
    echo 'edCanvas = document.getElementById("' . $textarea_id . '");</script>';
    /* echo 'console.log(edToolbar())</script>';  */
    echo '</div><hr width="60%"';
    $tab_index_count++;
    }
    }

    Thanks

Viewing 1 replies (of 1 total)
  • Thread Starter danielwiener

    (@danielwiener)

    I found a workaround for this. Not necessarily the best way.

    I downloaded quicktags from Alex King.
    http://alexking.org/projects/js-quicktags

    I gave the file a different name. Changed the name of the functions.

    Then called it in my “metabox” function like so:

    echo ' <script type="text/javascript">dw_edToolbar("' . $textarea_id . '")</script>';

    Where “$textarea_id” is the name of the particular custom meta box.

    It worked. A little funky since I am calling another script.

    I called the script in functions.php like so:

    add_action('admin_print_scripts', 'dw_quicktags');
    function dw_quicktags() {
    	wp_enqueue_script(
    		'dw_quicktags',
    		'/wp-content/themes/lesson_plans/js/dw_quicktags.js'
    	);
    }
Viewing 1 replies (of 1 total)
  • The topic ‘Custom Meta Boxes with Quicktags’ is closed to new replies.