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.

The pages like "about" will be created automatically when a new blog is created. Likewise I need some other pages which should appear automatically when a blog is created under my multisites.

How can I configure the default pages to be created with a new blog under a multisite?

For ex.: If I have a multisite on example.com. Every blog created under this site should have Home, About, My store, My address.

share|improve this question
3  
I actually plan on creating a plugin for this. I am planning to define an easily created format for saving and restoring a post to and from a text file and to even create a post in this format by hand by a non-technical person. But I haven't started work on it yet so I can only tell you about what I envision it will be. In the mean time, @kevtrout has a reasonable solution below. –  MikeSchinkel Aug 30 '10 at 18:58
    
@MikeSchinkel: I suppose it would be nice to A) Create template versions of each default page as a standard page, and B) Define those pages as 'default' using a form in the admin section. When an 'MU-style' blog is activated, the template pages are copied to that blog account. Seems like a great idea for the Multi-site uses of WP. My needs in the past have required default content to appear in the write-post textarea. Never did figure it out...new question perhaps? –  kevtrout Aug 30 '10 at 20:01
    
@kevtrout - write-post textarea? You mean post_content? If not then yeah, a new question. That's what SE is here for. :) –  MikeSchinkel Aug 31 '10 at 9:23

2 Answers 2

up vote 11 down vote accepted

I recommend creating a function in your functions.php file that ties to the action hook activate_blog. Use the WordPress functions get_pages() to see if your default pages exist. If they do not, create them with wp_insert_post.

add_action('activate_blog','my_default_pages');

function my_default_pages(){
    $default_pages = array('About','Home','My Store','My Address');
    $existing_pages = get_pages();

    foreach($existing_pages as $page){
        $temp[] = $page->post_title;
        }


    $pages_to_create = array_diff($default_pages,$temp);

    foreach($pages_to_create as $new_page_title){

            // Create post object
            $my_post = array();
            $my_post['post_title'] = $new_page_title;
            $my_post['post_content'] = 'This is my '.$new_page_title.' page.';
            $my_post['post_status'] = 'publish';
            $my_post['post_type'] = 'page';



            // Insert the post into the database
            $result = wp_insert_post( $my_post );

        }
        }

To test this function on your own site, try setting the hook to wp_head. It will run on each page load and insert the pages that don't exist, with the content in $my_post['post_content']. *Does the 'activate_blog' hook run when blogs are created in a multi-site context? I don't know.*

Refer to the codex page for wp_insert_post that I linked to for the complete list of default parameters available.

share|improve this answer
    
Thank you ! I will try it . –  user391 Aug 30 '10 at 15:08
    
I have grabbed the code you have given and pasted in my theme's functions.php with out any changes. And later I have created a new site to check whether it is created with newly added pages. But unfortunately I have not find any changes in new site or in main site. I think I committed mistake some where . –  user391 Sep 3 '10 at 11:06
    
Follow my recommendation to set the hook to wp_head above to test whether the code is working for you. Then look into exactly when the 'activate_blog' hook fires. –  kevtrout Sep 3 '10 at 11:31
1  
Sorry ! I am still unable to follow where to use wp_head and how to proceed .I am newer to wordpress.I know a little bit of php and not much familiar to coding . –  user391 Sep 3 '10 at 14:18
    
Change add_action('activate_blog','my_default_pages');, to add_action('wp_head','my_default_pages');. Then go read about action and filter hooks: codex.wordpress.org/Plugin_API/Action_Reference. In the end, you'll need to find the hook that runs when a new blog is activated, so that pages will be created at that time. I believe that hook is activate_blog but the documentation for it in the codex is sparse. Try googling for more info. I suggest using wp_head just to test the function above. When you know it works and have found the right hook to use, use that instead. –  kevtrout Sep 3 '10 at 20:18

use "wpmu_activate_blog" instead of "activate_blog". it worked for me. thanks

share|improve this answer
    
Thanks ! I will try it –  user391 Jan 11 '11 at 8:08

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.