Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I run a multisite install and I have removed the page attributes meta box from view for my users because I don't want them to be able to change templates. I would like them to be able to change the page parent though. I need to add a new meta box for pages that adds just the page parent selector back.

share|improve this question
add comment

2 Answers

Did just that for one of my plugins, recently...

function render($post) {
    $pages = wp_dropdown_pages(array('post_type' => 'page', 'exclude_tree' => $post->ID, 'selected' => $post->post_parent, 'name' => 'parent_id', 'show_option_none' => __('(no parent)'), 'sort_column'=> 'menu_order, post_title', 'echo' => 0));
    if (!empty($pages)) {
        ?>
        <p><strong><?php _e('Parent') ?></strong></p>
        <label class="screen-reader-text" for="parent_id"><?php _e('Landing Page') ?></label>
        <?php echo $pages; ?>
        <?php
    }
    ?>
    <?php
}

I implement my metaboxes as classes, hence the funny function name. I removed the menu order field which i originally kept in my metabox. I think it's a good idea to keep it.

You'll find the original 'attributes' metabox in wp-admin/includes/meta-boxes.php, btw., which is a nice library of code to have a look at if you implement custom metaboxes.

share|improve this answer
    
@wyrfel Thanks for the info! how would I register this as a metabox on the page editor? I know I have to ad some kind of code to a plugin or my functions.php in my theme but I'm lost on what to add –  user3617 Mar 2 '11 at 3:39
    
    
@wyrfel Thanks again, you are a life saver. One more question if you have the time. Do you think I need to do anything different because it's a multisite install? Again you rock, if your in the Bucks County, PA area sometime your in for a big fat kiss on the lips –  user3617 Mar 2 '11 at 4:26
    
@paul: Lol...how charming. I'm afraid i'm not the go-to gui for MU or BuddyPress kind of things. But i couldn't imagine there'd be anything different in regards to metaboxes on an MU system. –  wyrfel Mar 2 '11 at 4:33
    
@paul: BTW...just checked out some images from the Bucks County ;-) ...pretty pretty one must say. –  wyrfel Mar 2 '11 at 6:55
show 1 more comment

well thanks to the help of @wyrfel I was able to get this working. I had to edit the code you gave me some, and the code for adding meta boxes since this function is already part of the core. for anyone else looking here is what I finally used (whole thing added to theme's functions.php file)

// add page parent metabox
define('MY_WORDPRESS_FOLDER',$_SERVER['DOCUMENT_ROOT']);
define('MY_THEME_FOLDER',str_replace("\\",'/',dirname(__FILE__)));
define('MY_THEME_PATH','/' . substr(MY_THEME_FOLDER,stripos(MY_THEME_FOLDER,'wp-content')));

add_action('admin_init','my_meta_init');

function my_meta_init()
{ 
    // add a meta box for each of the wordpress page types: pages
    foreach (array('page') as $type) 
    {
        add_meta_box('my_all_meta', 'Page Parent', 'my_meta_setup', $type, 'side', 'low');
    }

    // add a callback function to save any data a user enters in
    //add_action('save_post','my_meta_save');
}

function my_meta_setup($post) {
$post_type_object = get_post_type_object($post->post_type);
    if ( $post_type_object->hierarchical ) {
        $pages = wp_dropdown_pages(array('post_type' => $post->post_type, 'exclude_tree' => $post->ID, 'selected' => $post->post_parent, 'name' => 'parent_id', 'show_option_none' => __('(no parent)'), 'sort_column'=> 'menu_order, post_title', 'echo' => 0));
        if ( ! empty($pages) ) {
?>
<p><strong><?php _e('Parent for this page:') ?></strong></p>
<label class="screen-reader-text" for="parent_id"><?php _e('Parent') ?></label>
<?php echo $pages; 
        }
    }
}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.