开发者

Can I create a page template from a plugin in Wordpress?

I am writing a payment processing plugin and I need several custom pages so I am wondering is there a w开发者_Python百科ay to generate them from the plugin?


You can generate pages in WordPress programatically by interfacing with the database.

This example creates a new page called "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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜