The MU forums have moved to WordPress.org

Setting up newly created blogs to default to the static About page (17 posts)

  1. tarmentano
    Member
    Posted 12 years ago #

    Hello,
    I am trying to set up my install of WPMU 2.6.5 so that when a person creates a blog on the system, it will default to the static "About" page as their blog homepage. The goal is to not have to make them go to "Settings > Reading > Front Page Displays, etc. Does anyone know how this can be done?

    Thanks for your time. Much appreciated!
    Terence

  2. VentureMaker
    Member
    Posted 12 years ago #

    Check new blog defaults plugin and wpmudev.org

  3. tarmentano
    Member
    Posted 12 years ago #

    Thanks a lot VentureMaker! I was looking around for hours yesterday and can't believe I didn't check the wpmudev site. I just kept doing google searches. I will give it a try and let you know what happens. Thanks again.

    Terence

  4. tarmentano
    Member
    Posted 12 years ago #

    Hi,
    I checked the New Blog Defaults plugin and it is helpful but didn't have what I was looking for. Let me explain what I want to do with more clarity:

    I set up my install of wpmu to automatically create 5 static pages, which it does beautifully. Two of those static pages are titled "Welcome" and "Blogs." My goal is to then have the system automatically choose the "Welcome" page as the default Front Page and the "Blog" page as the default Posts page. As you know, this can be done manually by the user through "Settings > Reading > Front Page Displays, etc. But my goal is to automate that process. Any help would be greatly appreciated. Thanks for your time.

    Best,
    Terence

  5. VentureMaker
    Member
    Posted 12 years ago #

    I think, still new defaults plugin has to be used. But it has to be modified to contain such option as well.

  6. andrea_r
    Moderator
    Posted 12 years ago #

    Yep. There's two plugins for new blog defaults, neither of which contain this specific code.

    But. if you can understand what's there, it's easy enough to add.

  7. tarmentano
    Member
    Posted 12 years ago #

    That plugin does look promising. Here is the New Blog Defaults plugin code for anyone that would like to take a stab at it and offer suggestions on how to set the Default Front Page displays - http://www.bgsuideal.com/code/new_blog_defaults_plugin.txt

    Any other ideas? Much thanks!

    Terence

  8. tarmentano
    Member
    Posted 12 years ago #

    RESOLVED! - I used the New Blog Defaults plugin and added the following code:
    go to wp-content > mu_plugins> cets_blog_defaults.php

    $cets_blogdefaults = array(
    // added the following code
    'show_on_front'=>'page',
    'page_on_front'=>2,
    'page_for_posts'=>7,

    //added the following code after update_option($key, $value);

    update_option('show_on_front', 'page');
    update_option('page_on_front', 2 );
    update_option('page_for_posts', 7 );

  9. jonperry
    Member
    Posted 11 years ago #

    Thanks this just saved me. I've been trying to figure this out for the past 2 days.

    Just a little note to add here for anyone else who needs this fix, in
    page_on_front'=2,
    The "2" refers to the ID# of the page you want to be your default home page.

    on 'page_for_posts'=>7, the "7" refers to the id of the desired post page.

  10. Ovidiu
    Member
    Posted 11 years ago #

    can someone also share the code to create additional pages upon blog creation? I think that can also be solved with this plugin, right?

    this is the code from wpmu-functions.php to create the First page but I really suck at coding, so how would the code look like we would need to isnert into the new blog defautls plugin to create additional pages as I don't want to hack core files?

    // First page
    1400 	    $wpdb->insert( $wpdb->posts, array(
    1401 	        'post_author' => $user_id,
    1402 	        'post_date' => $now,
    1403 	        'post_date_gmt' => $now_gmt,
    1404 	        'post_content' => __('This is an example of a WordPress page, you could edit this to put information about yourself or your site so readers know where you are coming from. You can create as many pages like this one or sub-pages as you like and manage all of your content inside of WordPress.'),
    1405 	        'post_excerpt' => '',
    1406 	        'post_title' => __('About'),
    1407 	        'post_name' => __('about'),
    1408 	        'post_modified' => $now,
    1409 	        'post_modified_gmt' => $now_gmt,
    1410 	        'post_status' => 'publish',
    1411 	        'post_type' => 'page',
    1412 	        'to_ping' => '',
    1413 	        'pinged' => '',
    1414 	        'post_content_filtered' => ''
    1415 	    ) );
    1416
    1417 	    // Flush rules to pick up the new page.
    1418 	    $wp_rewrite->init();
    1419 	    $wp_rewrite->flush_rules();
  11. boonika
    Member
    Posted 11 years ago #

    @tarmentano & jonperry

    How to set titles for those pages?

    Thanks

  12. tarmentano
    Member
    Posted 11 years ago #

    @Ovidiu

    I'm still trying to figure that out too. In the meantime, I just hacked the core files by copying and pasting that section (ie. //Second page, //Third page, etc), which is not the best solution but works.

    @Boonika

    Look at the code Ovidiu posted. You set the page titles in there. For example if you wanted to change the name of the "About" page, you could do it in that area.

  13. Ovidiu
    Member
    Posted 11 years ago #

    unfortunately, this plugin and this one: http://wpmudevorg.wordpress.com/project/New-Blog-Defaults still haven't merged and both have some unique features :-(

  14. kgraeme
    Member
    Posted 11 years ago #

    Which is the other plugin you're referring to, Ovidiu? I recall DeannaS saying she had looked at another blog defaults plugin with slightly different features, but the approach that it uses to set up defaults was fundamentally different enough that it wasn't possible to just merge the code into hers. It had to do with when the code gets called and where in the site provisioning steps the defaults get set.

  15. raskull
    Member
    Posted 11 years ago #

    To add a page called My Blog Page to all new blogs
    and to set the About Page as the front page
    and to set My Blog Page as the posts page:

    Start with your cets_blog_defaults.php file installed at
    wp-content > mu_plugins> cets_blog_defaults.php
    (download plugin at http://wpmudevorg.wordpress.com/project/New-Blog-Defaults )

    Add exactly what tarmentano (above) says:

    $cets_blogdefaults = array(
    // added the following code
    'show_on_front'=>'page',
    'page_on_front'=>2,
    'page_for_posts'=>7,
    
    //added the following code after update_option($key, $value);
    
    update_option('show_on_front', 'page');
    update_option('page_on_front', 2 );
    update_option('page_for_posts', 7 );

    If you haven't already somehow added more pages (eg through core hacking) then change the 7 to 3 in both places above.

    Then insert this at the end of cets_blog_defaults.php, before the ?>
    (Thank you http://gregorygrubbs.com/wordpress/how-to-give-wpmu-blogs-default-properties-theme-and-pages/ )

    function prime_the_blog($blog_id) {
    	// add_blog_option( $id, $key, $value ) at http://codex.wordpress.org/WPMU_Functions/add_blog_option
       add_blog_option($blog_id, 'generate_new_page', 'generate_new_page');
       switch_to_blog($blog_id);
       $postdata = array('post_parent' => 0,
       'post_status' => 'publish',
       'post_title'   => 'My Blog Page',
       'post_name'  => 'my-blog-page', /* the slug */
       'page_template' => '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', 'prime_the_blog');

    Now you have everything with no core hacking. I'm no expert; I just never give up. So let me know if this works for you, and please tell me what I code I could put for // your error handling code.

    In my case I also created this which I put on my page templates. It overrides the display of the page name (for instance About) when it is set to the front page to read My Site Name Home:

    <h1><?php if (is_front_page()) : echo bloginfo('name') . ' Home';
    		else : the_title();
    		endif; ?></h1>

    Used with wp_page_menu...

    wp_page_menu(array(
    		'show_home' => get_bloginfo('name') . ' Home',
    	));

    ...the default site navigation now looks like this for new blogs:
    My Site Name Home [a static front page]
    My Blog Page [posts page aka the blog]

  16. stacef
    Member
    Posted 11 years ago #

    This is great! Everything works, doing exactly what I needed.

    I had a problem initially with setting the template but I took a look at the code referenced at gregorygrubbs.com and realized I was missing a line that defines the theme where the template lives (at least in my case).

    Between switch_to_blog and $postdata, add this:
    switch_theme( $template, $stylesheet );
    in my case, for example:
    switch_theme('constructor', 'constructor');

    Hope this helps.
    Thanks,
    Stace

  17. hardline
    Member
    Posted 11 years ago #

    Is it possible to have the users pages and posts populated with the same pages and posts from the admin? Which will include the post content and everything for that post/page.

About this Topic

  • Started 12 years ago by tarmentano
  • Latest reply from hardline