The MU forums have moved to WordPress.org

Change default category and post (21 posts)

  1. nims
    Member
    Posted 16 years ago #

    Hi,

    When a new blog is created a default post "Hello World!" and a default category "Uncategorized" is created.

    How can we customize this. We need to create a different default post, say "Welcome" with our customized message and the default category to be say "general".

  2. andrea_r
    Moderator
    Posted 16 years ago #

    You'll have to edit a file. I think it's in /wp-includes/wpmu-functions.php

  3. nims
    Member
    Posted 16 years ago #

    Is there any plugin available for this.

  4. ekusteve
    Member
    Posted 16 years ago #

    I changed my defaults in the file andrea_r referenced above. If you have access to that file on the server it's not too difficult...just open it in a text editor and change the default category around line 1254 and you can change the content of the first post around line 1287...you can change a lot of other defaults there as well, like default links, comment, page, etc.

    I think you can change the content of the first post in the admin area of Mu...just go to Site Admin/Options to change it there, but you can't change the default category there.

    Not sure if there is a plugin for this.

    Steve

  5. nims
    Member
    Posted 16 years ago #

    Thanks could achieve it with your help guys.

  6. nims
    Member
    Posted 16 years ago #

    What if I need to create 2 or more default categories ?
    Which part of the code do I need to replicate ?
    code// Default category
    $wpdb->query("INSERT INTO $wpdb->categories (cat_ID, cat_name, category_nicename, category_count, category_description) VALUES ('0', '".addslashes(__('Uncategorized'))."', '".sanitize_title(__('Uncategorized'))."', 1, '')");
    $blogroll_id = $wpdb->get_var( "SELECT cat_ID FROM {$wpdb->sitecategories} WHERE category_nicename = 'blogroll'" );
    if( $blogroll_id == null ) {
    $wpdb->query( "INSERT INTO " . $wpdb->sitecategories . " (cat_ID, cat_name, category_nicename, last_updated) VALUES (0, 'Blogroll', 'blogroll', NOW())" );
    $blogroll_id = $wpdb->insert_id;
    }
    $wpdb->query("INSERT INTO $wpdb->categories (cat_ID, cat_name, category_nicename, link_count, category_description) VALUES ('{$blogroll_id}', '".addslashes(__('Blogroll'))."', '".sanitize_title(__('Blogroll'))."', 2, '')");
    $wpdb->query("INSERT INTO $wpdb->link2cat (link_id, category_id) VALUES (1, $blogroll_id)");
    $wpdb->query("INSERT INTO $wpdb->link2cat (link_id, category_id) VALUES (2, $blogroll_id)");
    code

  7. moriogawa
    Member
    Posted 16 years ago #

    Replicate your first line of code:

    $wpdb->query("INSERT INTO $wpdb->categories (cat_ID, cat_name, category_nicename, category_count, category_description) VALUES ('0', '".addslashes(__('Uncategorized'))."', '".sanitize_title(__('Uncategorized'))."', 1, '')");

    And simply change both instances of 'Uncategorized' to whatever you want your new category called. If you're adding a default post to your new default category, leave the second-to-last variable as '1', otherwise change it '0' since there won't be any posts there to start off with.

    Unfortunately, by default Blogroll's category ID will be set to 2, even if your new default category is occupying that ID number. To allow Blogroll to keep a unique category ID, take the second line:

    $blogroll_id = $wpdb->get_var( "SELECT cat_ID FROM {$wpdb->sitecategories} WHERE category_nicename = 'blogroll'" );

    and tack on '+a' right before the semicolon, where 'a' is the number of additional default categories you've added. There might be a cleaner way to do this, but this works for me.

  8. sarahd
    Member
    Posted 16 years ago #

    Does anyone know how to set up a few custom default categories in MU 1.3?

    I see the existing default category code in wpmu-functions.php, but this is a little different than what is described here.

  9. sarahd
    Member
    Posted 16 years ago #

    Never mind! In 1.3, I copied the code starting around line 1295 in wpmu-functions.php and added another category, changing the 'Uncategorized' to the new category title and changing the term_id (to 3 for a new category id) and count value (to 0 because I don't have any default posts). Like so:

    // Default category 3
    $cat_name = $wpdb->escape(__('First Stop Resources'));
    $cat_slug = sanitize_title(__('First-Stop-Resources'));
    $wpdb->query("INSERT INTO $wpdb->terms (term_id, name, slug, term_group) VALUES ('3', '$cat_name', '$cat_slug', '0')");
    $wpdb->query("INSERT INTO $wpdb->term_taxonomy (term_id, taxonomy, description, parent, count) VALUES ('3', 'category', '', '0', '0')");
  10. billdennis5
    Member
    Posted 15 years ago #

    Usefull thread, this one is.

  11. awarner20
    Member
    Posted 15 years ago #

    @ billdennis5

    I'll second that. I try to stay away from editing core files, and a plugin to achieve this would be a great project. However, I haven't been able to avoid making some core edits, so I advise that if you're not already, you should open notepad and keep some documentation of every core file edit you do.

    This has saved me a lot of frustration already when upgrading.

    Good luck all!

  12. Konstan
    Member
    Posted 15 years ago #

    Thats what I do, I have a text file with instructions on what to do everytime I upgrade, step by step :P

  13. wildebees
    Member
    Posted 15 years ago #

    Indeed very useful. Thank you.

  14. boonika
    Member
    Posted 15 years ago #

    Also look for:
    $wpdb->query( "UPDATE {$wpdb->terms} SET name = 'Articles', slug = 'articles' WHERE term_id = 1" );

    here:
    http://pastebin.com/f21c328aa

    MrBrian's solution

  15. mikesmobile
    Member
    Posted 15 years ago #

    Nims. Thanks for your original post. Your original question produced a lot of valuable feedback.

    Kudos to all.

    -Mike Thompson

  16. dwenaus
    Member
    Posted 15 years ago #

    is there any way to do this via a plugin using wpmu_new_blog hook? it seems like a better plan then editing core files, even if you track the changes. by the way, how exactly does the hook work, does it process after the entire function has run, or at the start.

  17. dwenaus
    Member
    Posted 15 years ago #

    I noticed with your direct addition of the categories into the new blog database, it works, but the new category does not get added to the main sitecategories table. Could this be a problem down the road? I'm not all that sure. does anyone here know?

    a solution might be to do what the code does a few lines down with the blogroll. it looks to see if one exists in sitecategories then uses it if it does, otherwise it creates it.
    here is the code I wrote that seems to add everything properly:

    // Extra Default categories
    	$cat_name = __('Default Category Name');
    	$cat_slug = sanitize_title($cat_name);
    
    	$category_id = $wpdb->get_var( $wpdb->prepare( "SELECT cat_ID FROM {$wpdb->sitecategories} WHERE category_nicename = %s", $cat_slug ) );
    	if( $category_id == null ) {
    		$wpdb->insert( $wpdb->sitecategories, array('cat_ID' => 0, 'cat_name' => $cat_name, 'category_nicename' => $cat_slug, 'last_updated' => current_time('mysql')) );
    		$category_id = $wpdb->insert_id;
    	}
    	$wpdb->insert( $wpdb->terms, array('term_id' => $category_id, 'name' => $cat_name, 'slug' => $cat_slug, 'term_group' => 0) );
    	$wpdb->insert( $wpdb->term_taxonomy, array('term_id' => $category_id, 'taxonomy' => 'category', 'description' => '', 'parent' => 0, 'count' => 0) );

    It makes sense to make a funciton out of this (or much better a plugin) so that you could add lets say 5 new categories without the duplication.

  18. dwenaus
    Member
    Posted 15 years ago #

    I decided to go ahead and create a plugin for this, so no more editing the core code. It is here:

    http://natureofmind.org/?p=30

  19. fastandeasy
    Member
    Posted 15 years ago #

    Hello everyone!, I am new here, actully I am still tryding to do the installation, but my plan is create more than 3 blogs, that I can manage in one console. I wonder is I public a post that post can you public in every blog, or I need to create the same post ijn every blogs that I have?
    Cheers...
    Jennifer

  20. andrea_r
    Moderator
    Posted 15 years ago #

    Each blog is seperate. You have to post in *each* blog.

  21. Ovidiu
    Member
    Posted 15 years ago #

    the plugin linked here is really great, but how could I get rid of the uncategorized category that automatically gets created without hacking core files?
    Could this plugin also delete or suppress that category and set its category#1 as default maybe?

About this Topic