Support » Networking WordPress » How to give all new WPMS sites default predefined pages

Viewing 9 replies - 1 through 9 (of 9 total)
  • Hi jim9! That’s one of the things I came here to research, so I was happy to find your link.

    This works for me when added to my functions.php file in the theme for my main site:

    function dscp_initialize_blog($blog_id) {
        switch_to_blog($blog_id);
        switch_theme('litsam_books', 'litsam_books');
    
        $postdata = array('post_parent' => 0,
        'post_status' => 'publish',
        'post_title'   => 'DESCRIPTIVE TITLE',
        'post_name'  => 'descriptive-title', /* the slug */
        'page_template' => 'some-page.php',
        'post_type'   => 'page');
        $newid = wp_insert_post($postdata);
        if ($newid && !is_wp_error($newid)) {
           add_meta($newid);
        } else {
           // your error handling code
        }
     }
    
    add_action('wpmu_new_blog', 'dscp_initialize_blog');

    Note that’s *exactly* the original code (adjusted for a theme I have installed)with just the first line removed. The first line, best I can tell, set an option on the blog that wasn’t relevant to the rest of the discussion. (I’m not sure what it was for.)

    If it’s not working for you, what is failing?

    Hi Jim,

    There are two plugins that I use to achieve this – you don’t need both, either one will do it, just a little bit differently.

    http://wordpress.org/extend/plugins/default-blog-options/
    -I’ve been using that plugin for the past 1.5 year without any problems on a current install. Created maybe 50 blogs using it without any problems.

    http://wpebooks.com/replicator/
    -Never used this one, but heard a lot of good things about it.

    Hi shastaw,

    I am not very familiar with using wp functions so I would like to ask you
    should I change the first “litsam_books” to the folder’s name of my theme. and the second one to the stylesheet name?

    'some-page.php' is this the same for all themes?

    Hi rickymurphy,

    The plugin http://wordpress.org/extend/plugins/default-blog-options/
    lists all the pages that I have created before. but it does not list any page I have made after the installation.
    Does that happens with you?

    Yes, you would change “litsam_books” to the name of your theme folder. The stylesheet option will usually be the same unless you’re using a child theme, in which case you’d use that folder.

    The other thing that might not be totally obvious is the line:

    'page_template' => 'some-page.php',

    This lets you set a non-default template, just like that little pull-down on the page where you create new pages, but if you leave it out it’ll just pick the default template for that page. (page.php or index.php, or whatever the template hierarchy says it should be.)

    If this isn’t making any sense you may be better off with a plug-in. I haven’t used the ones above, but it looks like default-blog-options would basically allow you to create one site as a template and then duplicate it. That may be much easier if you’re new to this or uncomfortable with coding.

    It works but it does not copy the page content. Does it do the same in your site?

    Jim, I’m not clear on who you’re replying to, or which potential solution doesn’t copy the content…if you mean the plug-in, I haven’t used it.

    If you mean the code above, then no, it only duplicates the page. The way I’ll be utilizing it is by including the static information in the template (that’s the part I mentioned above: page_template => some-page.php) and letting the new blog-user can customize the post part of that page. (One of mine, for example, is a copyright page where the user needs to customize the author and copyright date.)

    You could also create a template for the page that simply doesn’t include the loop at all, and is just the static content.

    You said you’re not familiar with the functions.php, so I’m wondering if you’re familiar with terms like “the loop” and writing template pages? If not, you’ll likely need to start there. (Or get the plug-in to work for you.)

    I was talking about the code not the plugins. I am somehow familiar with template design tags so I have good idea about terms like “the loop” and writing template pages.
    Most likely I will use one of the plugins currently as it is the easier way now. However I still like to know how to copy the page content as I believe it is not more than one additional line so if you know it please tell me what to add to the above code. Thanks

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    Lead Plugin Wrangler

    The plugin http://wordpress.org/extend/plugins/default-blog-options/
    lists all the pages that I have created before. but it does not list any page I have made after the installation.

    Yeah, you have to update the default blog options if you want new pages added.

    There are also plugins like http://wpebooks.com/replicator/ which let you copy from a ‘main’ blog.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘How to give all new WPMS sites default predefined pages’ is closed to new replies.