我可以从Wordpress中的插件创建页面模板吗?

时间:2011-01-13 21:53:18

标签: wordpress

我正在编写支付处理插件,我需要几个自定义页面,所以我想知道有没有办法从插件生成它们?

1 个答案:

答案 0 :(得分:1)

您可以通过与数据库连接以编程方式在WordPress中生成页面。

此示例创建一个名为“Books”的新页面

function books_page_setup() {
    global $wpdb, $user_ID;
    if ( get_site_option('books_page_setup') != 'complete' && is_site_admin() ) {
        $page_count = $wpdb->get_var("SELECT COUNT(*) FROM " . $wpdb->posts . " WHERE post_name = 'books' AND post_type = 'page'");
        if ( $page_count < 1 ) {
            $wpdb->query( "INSERT INTO " . $wpdb->posts . " ( 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 ( '" . $user_ID . "', '" . current_time( 'mysql' ) . "', '" . current_time( 'mysql' ) . "', '', 'Books', '', 'publish', 'closed', 'closed', '', 'books', '', '', '" . current_time( 'mysql' ) . "', '" . current_time( 'mysql' ) . "', '', 0, '', 0, 'page', '', 0 )" );
        }
        update_site_option('books_page_setup', 'complete');
    }
}

Interfacing With the Database INSERT rows