2011-01-13 7 views

答えて

1

WordPressでページを生成するには、データベースとのインタフェースをプログラムで行うことができます。

この例では、「ブック」あなたの答えのための

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

おかげと呼ばれる新しいページを作成しますが、ページ内にそのようにPHPコードを挿入することが可能だろうか?私はPHPコードを挿入するためにプログラムでページテンプレートを作成する方法が必要だと思います。私は間違っているかもしれません。 – dchakarov

関連する問題