WordPress.org

Ready to get started?Download WordPress

Forums

How to give all new WPMS sites default predefined pages (10 posts)

  1. jim9
    Member
    Posted 2 years ago #

    Hi,

    I am trying to give all new WPMS new sites a predefined default pages. I have searched the internet for a solution and found this

    http://gregorygrubbs.com/wordpress/how-to-give-wpmu-blogs-default-properties-theme-and-pages/

    But the code on that page is too old now

    [Code moderated as per the Forum Rules. Please use the pastebin]

    so could someone please updated for me?

    Thanks

  2. shastaw
    Member
    Posted 2 years ago #

    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?

  3. rickymurphy
    Member
    Posted 2 years ago #

    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.

  4. jim9
    Member
    Posted 2 years ago #

    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?

  5. jim9
    Member
    Posted 2 years ago #

    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?

  6. shastaw
    Member
    Posted 2 years ago #

    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.

  7. jim9
    Member
    Posted 2 years ago #

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

  8. shastaw
    Member
    Posted 2 years ago #

    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.)

  9. jim9
    Member
    Posted 2 years ago #

    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

  10. 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.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.