WordPress.org

Ready to get started?Download WordPress

Forums

create a custom page on theme activation (2 posts)

  1. Marc P Gangmei
    Member
    Posted 4 years ago #

    I want to create a page with a custom template automatically upon theme activation. Is this possible?

    I think it can be done as wordpress has default about me page.

    Can anyone show me some way?

  2. keithd77
    Member
    Posted 3 years ago #

    Hi,

    You can add something like this in the functions.php file.

    if ( is_admin() && isset($_GET['activated'] ) && $pagenow == "themes.php" ) {
    global $wpdb;

    $sql = "

    INSERT INTO $wpdb->posts (

    ID ,

    post_author ,

    post_date ,

    post_date_gmt ,

    post_content ,

    post_title ,

    post_excerpt ,

    post_status ,

    comment_status ,

    ping_status ,

    post_password ,

    post_name ,

    to_ping ,

    pinged ,

    post_modified ,

    post_modified_gmt ,

    post_content_filtered ,

    post_parent ,

    guid ,

    menu_order ,

    post_type ,

    post_mime_type ,

    comment_count

    )

    VALUES (

    NULL , '1', '0000-00-00 00:00:00', '0000-00-00 00:00:00', 'aaa', 'page-title', '', 'publish', 'open', 'open', '', 'page-title', '', '', '0000-00-00 00:00:00', '0000-00-00 00:00:00', '', '0', '', '0', 'page', '', '0'

    )

    ";

    $wpdb->query($sql);

    $page_id = $wpdb->insert_id;

    $sql = "insert into ". $wpdb->postmeta . "(post_id, meta_key, meta_value) values($page_id, '_wp_page_template', 'custom-template.php')";

    $wpdb->query($sql);

    }

Topic Closed

This topic has been closed to new replies.

About this Topic