The MU forums have moved to WordPress.org

Default Pages & Content (43 posts)

  1. Jshwaz44
    Member
    Posted 15 years ago #

    When I create a new blog, I would like it to automatically create a number of static-pages populated with content. The user needs to edit these pages so they can't be hard coded into the template.

    It looks like default template and blogroll links have already been figured out. Any ideas on default pages with content?

  2. lunabyte
    Member
    Posted 15 years ago #

    It also adds a default "about" page.

    Duplicating that action shouldn't be difficult.

  3. drmiketemp
    Member
    Posted 15 years ago #

    Considering we've discussed it in the past a number of times, I would think a search for 'default page' or whatever else content is wanted here in the forums would pull it right up.

    Take a look at your wp-includes/wpmu-functions.php file for a bit labeled 'First Page' for where this is currently done. Just add it the additional lines that you need using that as a model.

    Hope this helps,
    -drmike

  4. Jshwaz44
    Member
    Posted 15 years ago #

    I actually did run a search and couldn't find the info you just gave me, but thank you!

  5. drmiketemp
    Member
    Posted 15 years ago #

    Not a problem.

  6. Jshwaz44
    Member
    Posted 15 years ago #

    Okay, I figured out how to crate a page, but what about a sub-page?

  7. Jshwaz44
    Member
    Posted 15 years ago #

    For anyone else who comes across this thread and needs a little more instruction the line you are editing looks like this:

    $wpdb->query("INSERT INTO $wpdb->posts (post_author, post_date, post_date_gmt, post_content, post_excerpt, post_title, post_category, post_name, post_modified, post_modified_gmt, post_status, post_type, to_ping, pinged, post_content_filtered) VALUES ('$user_id', '$now', '$now_gmt', '".$wpdb->escape(__('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.'))."', '', '".$wpdb->escape(__('About'))."', '0', '".$wpdb->escape(__('about'))."', '$now', '$now_gmt', 'publish', 'page', '', '', '')");

    The section that starts 'This is an example of a WordPress page' is a the content of the page.

    The first About is the title of the page

    The second about is what will show up in the URL

    I have no idea what the rest of the line of code does. Is this documented somewhere?

  8. lunabyte
    Member
    Posted 15 years ago #

    The second "about" (lowercase) is the page slug, The page content is pretty obvious.

  9. drmiketemp
    Member
    Posted 15 years ago #

    What's within the VALUES matches up with the first half of the line. You may want to look at the database and see how it looks after a blog gets created.

  10. Jshwaz44
    Member
    Posted 15 years ago #

    I looked around the database and couldn't find where to look. Any ideas?

  11. Jshwaz44
    Member
    Posted 15 years ago #

    It looks like the post_parent is the setting that determines if something is a sub-page. However, this isn't an option in the First Page code. It is an option in the chunk of code directly above this is wpmu-function.php under //First Post. Any thoughts?

  12. Jshwaz44
    Member
    Posted 15 years ago #

    Okay figured it out. For anyone else who wants to create a subpage by default when the blog gets created.
    1. Duplicate the first line of code under //First Page that starts with $wpdb->query("INSERT INTO $wpdb-> posts to create a new page by default
    2. On the new entry add post_parent to the end of this section
    (post_author, post_date, post_date_gmt, post_content, post_excerpt, post_title, post_category, post_name, post_modified, post_modified_gmt, post_status, post_type, to_ping, pinged, post_content_filtered)
    3. At the end of VALUES line of code
    ('$user_id', '$now', '$now_gmt', '".$wpdb->escape(__('content'))."', '', '".$wpdb->escape(__('About'))."', '0', '".$wpdb->escape(__('about'))."', '$now', '$now_gmt', 'publish', 'page', '', '', '')") enter the page ID that you want to be the parent of the subpage.
    Since the First Post takes up ID 1, The First Page stats at ID 2 and goes up from there. ie. The first
    $wpdb->query("INSERT INTO $wpdb->posts
    is ID 2, the second
    $wpdb->query("INSERT INTO $wpdb->posts
    is ID 3.

    The finished code with one main page with a subpage would look like this

    // First page
    $wpdb->query("INSERT INTO $wpdb->posts (post_author, post_date, post_date_gmt, post_content, post_excerpt, post_title, post_category, post_name, post_modified, post_modified_gmt, post_status, post_type,  to_ping, pinged, post_content_filtered) VALUES ('$user_id', '$now', '$now_gmt', '".$wpdb->escape(__('Enter content here'))."', '', '".$wpdb->escape(__('About Us'))."', '0', '".$wpdb->escape(__('about'))."', '$now', '$now_gmt', 'publish', 'page', '', '', '')");
    $wpdb->query("INSERT INTO $wpdb->posts (post_author, post_date, post_date_gmt, post_content, post_excerpt, post_title, post_category, post_name, post_modified, post_modified_gmt, post_status, post_type, to_ping, pinged, post_content_filtered, post_parent) VALUES ('$user_id', '$now', '$now_gmt', '".$wpdb->escape(__('Enter subpage content here'))."', '', '".$wpdb->escape(__('Resources'))."', '0', '".$wpdb->escape(__('resources'))."', '$now', '$now_gmt', 'publish', 'page','', '', '','2')");
    $wpdb->query( "INSERT INTO $wpdb->post2cat (<code>rel_id</code>, <code>post_id</code>, <code>category_id</code>) VALUES (2, 2, 1)" );
  13. jlsniu
    Member
    Posted 14 years ago #

    I've tried to follow this to add in 4 new pages to my default blogs. I have also changed the name of the default blogroll category. Anyone care to take a look and tell me what went wrong.

    I get the pages created and the default blogroll category changed but I dont get the default pages linked to the blogroll category. If I go into them individually after the new blog is created, the default blog category is checked but not until I hit save does it register and populate the category column on the summary table.

    // Default link category
    $cat_name = $wpdb->escape(__('Alumni Services'));
    $cat_slug = sanitize_title(__('Alumni Services'));
    $blogroll_id = $wpdb->get_var( "SELECT cat_ID FROM {$wpdb->sitecategories} WHERE category_nicename = '$cat_slug'" );
    if( $blogroll_id == null ) {
    $wpdb->query( "INSERT INTO " . $wpdb->sitecategories . " (cat_ID, cat_name, category_nicename, last_updated) VALUES (0, '$cat_name', '$cat_slug', NOW())" );
    $blogroll_id = $wpdb->insert_id;
    }
    $wpdb->query("INSERT INTO $wpdb->terms (term_id, name, slug, term_group) VALUES ('$blogroll_id', '$cat_name', '$cat_slug', '0')");
    $wpdb->query("INSERT INTO $wpdb->term_taxonomy (term_id, taxonomy, description, parent, count) VALUES ('$blogroll_id', 'link_category', '', '0', '0')");

    update_option('default_link_category', $blogroll_id);

    // Default links
    $wpdb->query("INSERT INTO $wpdb->links (link_url, link_name, link_category, link_owner, link_rss) VALUES ('https://alumni.gsb.stanford.edu/events/calendar/index.html', 'Calendar', 1356, '$user_id', '');");
    $wpdb->query("INSERT INTO $wpdb->links (link_url, link_name, link_category, link_owner, link_rss) VALUES ('https://alumni.gsb.stanford.edu/chapters/index.html', 'Networking', 1356, '$user_id', '');");
    $wpdb->query("INSERT INTO $wpdb->links (link_url, link_name, link_category, link_owner, link_rss) VALUES ('https://alumni.gsb.stanford.edu/lifelonglearning/index.html', 'Lifelong Learning', 1356, '$user_id', 'https://alumni.gsb.stanford.edu/rss/lifelonglearning.xml');");
    $wpdb->query("INSERT INTO $wpdb->links (link_url, link_name, link_category, link_owner, link_rss) VALUES ('https://alumni.gsb.stanford.edu/career/index.html', 'Career Services', 1356, '$user_id', 'https://alumni.gsb.stanford.edu/rss/career.xml');");
    $wpdb->query("INSERT INTO $wpdb->links (link_url, link_name, link_category, link_owner, link_rss) VALUES ('https://alumni.gsb.stanford.edu/help/index.html', 'Help', 1356, '$user_id', '');");

    $wpdb->query( "INSERT INTO $wpdb->term_relationships (object_id, term_taxonomy_id) VALUES (1, $blogroll_id)" );
    $wpdb->query( "INSERT INTO $wpdb->term_relationships (object_id, term_taxonomy_id) VALUES (2, $blogroll_id)" );
    $wpdb->query( "INSERT INTO $wpdb->term_relationships (object_id, term_taxonomy_id) VALUES (3, $blogroll_id)" );
    $wpdb->query( "INSERT INTO $wpdb->term_relationships (object_id, term_taxonomy_id) VALUES (4, $blogroll_id)" );
    $wpdb->query( "INSERT INTO $wpdb->term_relationships (object_id, term_taxonomy_id) VALUES (5, $blogroll_id)" );

  14. indojepang
    Member
    Posted 14 years ago #

    is it possible to asssign a page template? to particular Page created?
    how can i do this?

  15. boonika
    Member
    Posted 14 years ago #

    Good question... maybe inside wpmu-functions.php? See how it was done for 'About' page.

  16. indojepang
    Member
    Posted 14 years ago #

    have no clue about the code use for page template :(
    what is it? the database don't give the answer, it look the same for all post

  17. indojepang
    Member
    Posted 14 years ago #

    have no clue about the code use for page template :(
    what is it? the database don't give the answer, it look the same for all post

  18. boonika
    Member
    Posted 14 years ago #

    I think that page.php is assigned to new page by default. You can always change page template (for pages you're about to create) inside the administration.

  19. andrea_r
    Moderator
    Posted 14 years ago #

    The template files have to have a page template, and an alternate if you want one.

    http://codex.wordpress.org/Pages#Page_Templates

  20. indojepang
    Member
    Posted 14 years ago #

    yes i have my template file for that, just have to assign that particular 'page-template.php', but don't know how andrea..

    One more thing.. since i don't want to mess up with core files, i just duplicate the code to my 'function.php' in my theme, but i got infinite page created over and over.

    how to make it only once?

    Thank u for your help..

  21. indojepang
    Member
    Posted 14 years ago #

    4 Boonika:
    yes, but it will be easier to make it automatically.
    don't want to change it all the time :p

    i need that page-template.php for my particular Page & page.php 4 regular Pages.

  22. andrea_r
    Moderator
    Posted 14 years ago #

    When you write a new page, pick the page template to use on the right hand side.

    It's pretty basic stuff, and was also included in the link I posted.

  23. boonika
    Member
    Posted 14 years ago #

    @andrea

    I think that he wants to have those pages assigned to every new user-blog created so he don't have to do it manually. He also wants to have different page templates assigned to different pages... so he don't have to do it manually:)

  24. andrea_r
    Moderator
    Posted 14 years ago #

    Then he'll have to write a script. :)

  25. indojepang
    Member
    Posted 14 years ago #

    Thanks Boonika for clearing me out.. :D

    @andrea yes I have to write it.. the problem now, what is the code for pointing the 'page template'?

    WPMU so lack of documentation :(

  26. MrBrian
    Member
    Posted 14 years ago #

    page templates are core of wordpress. They're set in "postmeta" table.

  27. indojepang
    Member
    Posted 14 years ago #

    yes! thank u MrBrian Sir! found it '_wp_page_template'

    So guess I have to add INSERT INTO $wpdb->postmeta (_wp_page_template) VALUES ('page-template.php') isn't it?

    Since I don't know how to write it, can somebody show me how to combine this with INSERT INTO &wpdb->posts?

  28. MrBrian
    Member
    Posted 14 years ago #

    Do you mean how to create a page in wpdb->posts?

  29. indojepang
    Member
    Posted 14 years ago #

    the idea is to create an automatically page with particular page-template.php..

    Have no luck with this:

    $wpdb->query("INSERT INTO $wpdb->posts (post_author, post_date, post_date_gmt, post_content, post_excerpt, post_title, post_category, post_name, post_modified, post_modified_gmt, post_status, post_type, to_ping, pinged, post_content_filtered) VALUES ('$user_id', '$now', '$now_gmt', '".$wpdb->escape(__(''))."', '', '".$wpdb->escape(__('Discography'))."', '0', '".$wpdb->escape(__('discography'))."', '$now', '$now_gmt', 'publish', 'page', '', '', '')");
    $wpdb->query("INSERT INTO $wpdb->postmeta (_wp_page_template) VALUES ('page-discography.php')");

    I want to have a Page named=Discography, with page-template=page-discography.php assign with it.

    Hope I get help with this..

  30. MrBrian
    Member
    Posted 14 years ago #

    You're postmeta query is completely wrong. Example of proper query below:

    $wpdb->query("insert into $wpdb->postmeta (post_id,meta_key,meta_value) values ('15','_wp_page_template','templatefile.php')");

    Replace 15 with the post_id of your first query.

About this Topic

  • Started 15 years ago by Jshwaz44
  • Latest reply from benlagrone