The MU forums have moved to WordPress.org

Default Pages (18 posts)

  1. visiturebrandon
    Member
    Posted 14 years ago #

    I see a lot of posts about getting static page to be the default front page for a newly created blog. But how do I just create default pages. I would like to have about seven pages that automatically get created when a new blog is created.

    Thanks,
    Brandon

  2. visiturebrandon
    Member
    Posted 14 years ago #

    It would be great if I could do the same with categories.

  3. cafespain
    Member
    Posted 14 years ago #

    I don't think there is a plugin, yet, that does default pages.

  4. tdjcbe
    Member
    Posted 14 years ago #

    http://wpmudevorg.wordpress.com/project/New-Blog-Defaults

    Try coping and pasting the Default Page code out of the /wp-include/wpmu-funxctions.php file, but modified with what you need changed.

  5. Person
    Member
    Posted 14 years ago #

    I haven't tried it, but you could always hardcode it into wpmu-functions.php (below the //first page, insert it right above // Default comment)

    // Second page
    	$wpdb->insert( $wpdb->posts, array(
    		'post_author' => $user_id,
    		'post_date' => $now,
    		'post_date_gmt' => $now_gmt,
    		'post_content' => __('BLAHBLAHBLAH'),
    		'post_excerpt' => '',
    		'post_title' => __('2ND PAGE'),
    		'post_category' => 0,
    		'post_name' => __('pagetwo'),
    		'post_modified' => $now,
    		'post_modified_gmt' => $now_gmt,
    		'post_status' => 'publish',
    		'post_type' => 'page',
    		'to_ping' => '',
    		'pinged' => '',
    		'post_content_filtered' => ''
    	) );
    
    	// Flush rules to pick up the new page.
    	$wp_rewrite->init();
    	$wp_rewrite->flush_rules();
  6. tdjcbe
    Member
    Posted 14 years ago #

    We talked about this a week or two ago but I can't find it right off.

  7. wwhite@parkerwhitepruitt.com
    Member
    Posted 14 years ago #

    Hi,
    Im new here and have tried using the above code in the proper file. It does not seem to work. Is there another approach to having several default pages in each wpmu blog that is created?
    wjwjr

  8. Ovidiu
    Member
    Posted 14 years ago #

    @wwhite@parkerwhitepruitt.com:

    what does the code look like that you tried?

    besides, there are really too many plugins that share features out there :-( I really love this plugin http://wpmudevorg.wordpress.com/project/New-Blog-Defaults but its missing the default pages feature, so I have ot use this one in addition: http://wpmudevorg.wordpress.com/project/blog-templates

    I'd really love if the authors, could incorporate all features into one of them :-(

  9. wwhite@parkerwhitepruitt.com
    Member
    Posted 14 years ago #

    thanks for the reply. The blog-templates shows up in my control panel, i set the options, but when i create a new blog the pages are not there. There must be a setting i am missing. Do you know of any documentation?
    thanks
    wjwjr

  10. Ovidiu
    Member
    Posted 14 years ago #

    unfortunately not. haven't actively used that plugin either.

  11. vlieg69
    Member
    Posted 14 years ago #

    I have looked everywhere and was already coding in the core.. but I have put it in my own plugin now and hardcoded the pages there:
    (just put it in plugins-mu)

    function change_newblog_defaults( $blog_id, $user_id ){
     global $wpdb, $current_site, $wp_rewrite;
        //--change to new blog
        switch_to_blog($blog_id);
    //make page
        $wpdb->insert( $wpdb->posts, array(
    		'post_author' => $user_id,
    		'post_date' => $now,
    		'post_date_gmt' => $now_gmt,
    		'post_content' => __('This is the content'),
    		'post_excerpt' => '',
    		'post_title' => __('Pagetitle'),
    		'post_name' => __('Pagename'),
    		'post_modified' => $now,
    		'post_modified_gmt' => $now_gmt,
    		'post_status' => 'publish',
    		'post_type' => 'page',
    		'to_ping' => '',
    		'pinged' => '',
    		'post_content_filtered' => ''
    	) );
      //inserted id
      $page_id = $wpdb->insert_id;
    
      //change template inserted page
      $wpdb->query("insert into $wpdb->postmeta (post_id,meta_key,meta_value) values ($page_id,'_wp_page_template','templatefile.php')");
    //restore blog
     restore_current_blog();
    }
    add_action('wpmu_new_blog', 'change_newblog_defaults' );

    You can then also add a subpage: just add 'post_parent' to the values in creating a page

  12. pusbucket
    Member
    Posted 14 years ago #

    Try coping and pasting the Default Page code out of the /wp-include/wpmu-funxctions.php file, but modified with what you need changed.

    Thanks tdjcbe, this suited my needs perfectly. Now, how could those pages be created with order? I don't see a 'post_order' field in the docs.

  13. tarmentano
    Member
    Posted 14 years ago #

    @vlieg69

    That solution is awesome. Thanks for creating a plugin that creates pages dynamically. Do you plan on supporting it or having the plugin officially hosted somewhere?

    Terence

  14. ljmyers
    Member
    Posted 14 years ago #

    Hi everyone,

    I have used the code found in wpmu-functions.php. . .

    // Second page
    	$wpdb->insert( $wpdb->posts, array(
    		'post_author' => $user_id,
    		'post_date' => $now,
    		'post_date_gmt' => $now_gmt,
    		'post_content' => __('Content of new page.'),
    		'post_excerpt' => '',
    		'post_title' => __('Second Page'),
    		'post_name' => __('second-page'),
    		'post_modified' => $now,
    		'post_modified_gmt' => $now_gmt,
    		'post_status' => 'publish',
    		'post_type' => 'page',
    		'to_ping' => '',
    		'pinged' => '',
    		'post_content_filtered' => ''
    	) );

    by editing to create a second page on all new blogs and it seems to be working fine. What I am wondering is . . .

    I have created a template in the theme that this page will need to use in every new blog. Is there a way to edit this code to have this new page auto choose that specific template upon creation or will I have to settle for having my users do it manually?

    As always, thanks so much for your help.

  15. stacef
    Member
    Posted 14 years ago #

    The plugin from vlieg69 works (nearly) flawlessly, adding the page and the template (thanks, vlieg69!). For some reason, though, it doesn't seem to like the $user_id variable. Rest of the code still executes, though; just doesn't assign an author to the page. Any ideas?

    Separate but related: any thoughts on how to default the front page to a static page based on this newly created page?

    Thanks for any direction.
    Stace

  16. chelgeson
    Member
    Posted 13 years ago #

    I just tried the plugin from vlieg69 and on the activate page it gives me this error message.

    Warning: Missing argument 2 for change_newblog_defaults() in /public_html/wp-content/mu-plugins/cets_blog_defaults.php on line 1453

    I just added vlieg69's function into the cets_blog_defaults plugin thats why line number and file name....

    anyone know why I am getting this error?

    Thanks
    Cody

  17. chelgeson
    Member
    Posted 13 years ago #

    just wanted to update everyone...I found this thread
    http://wordpress.org/support/topic/298291?replies=3

    so I revised the last line of vlieg69's code above to

    add_action('wpmu_new_blog', 'new_blog_page', 100, 2 );

    and everything worked perfectly!

    Thanks
    Cody

  18. asyraf9
    Member
    Posted 13 years ago #

    Hi folks, just wanted to answer a few questions I had that other people here asked as well, which were:

    1) page ordering
    2) how to set a page as a front page

    so here's my code snippet

    $wpdb->insert( $wpdb->posts, array(
    		'post_author' => $user_id,
    		'post_date' => $now,
    		'post_date_gmt' => $now_gmt,
    		'post_content' => __('Welcome to my Homepage!'),
    		'post_excerpt' => '',
    		'post_title' => __('Home'),
    		'post_name' => __('home'),
    		'post_modified' => $now,
    		'post_modified_gmt' => $now_gmt,
    		'post_status' => 'publish',
    		'post_type' => 'page',
    		'to_ping' => '',
    		'pinged' => '',
    		'post_content_filtered' => '',
    		'menu_order' => -2,
    		'comment_status' => false,
    		'ping_status' => false
    	) );
      //inserted id
      $page_id = $wpdb->insert_id;
    
      update_option("show_on_front", "page");
      update_option("page_on_front", $page_id);
    
      //change template inserted page
      $wpdb->query("insert into $wpdb->postmeta (post_id,meta_key,meta_value) values ($page_id,'_wp_page_template','templatefile.php')");

    'menu_order' is the setting you need to put in to set page ordering.

    the two lines of 'update_option' is how you set the page to be the default front page.

    you will also need to tell wordpress the alternative page it will put your blog listings on. for that page, replace both 'update_option' lines with this single line:

    update_option("page_for_posts", $page_id);

    good luck!

About this Topic

  • Started 14 years ago by visiturebrandon
  • Latest reply from asyraf9