james-riter

Make multiple pages,set template,content theme wordpress

Aug 8th, 2013
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.07 KB | None | 0 0
  1. if (isset($_GET['activated']) && is_admin()){
  2.     add_action('init', 'create_initial_pages');
  3. }
  4. function create_initial_pages() {
  5.  
  6. $pages = array(
  7.      // Page Title and URL (a blank space will end up becomeing a dash "-")
  8.     'Services' => array(
  9.         // Page Content     // Template to use (if left blank the default template will be used)
  10.         'Services Content'=>'page-bottom-sidebar.php'),
  11.    
  12.     'Prices' => array(
  13.         'Prices Content'=>'page-wide.php'),
  14.    
  15.     'F A Q' => array(
  16.         'FAQ Content'=>' '),
  17. );
  18.  
  19. foreach($pages as $page_url_title => $page_meta) {
  20.         $id = get_page_by_title($page_url_title);
  21.        
  22.     foreach ($page_meta as $page_content=>$page_template){
  23.     $page = array(
  24.         'post_type'   => 'page',
  25.         'post_title'  => $page_url_title,
  26.         'post_name'   => $page_url_title,
  27.         'post_status' => 'publish',
  28.         'post_content' => $page_content,
  29.         'post_author' => 1,
  30.         'post_parent' => ''
  31.     );
  32.  
  33.     if(!isset($id->ID)){
  34.         $new_page_id = wp_insert_post($page);
  35.         if(!empty($page_template)){
  36.                 update_post_meta($new_page_id, '_wp_page_template', $page_template);
  37.         }
  38.     }
  39.  }
  40. };
  41. }
Advertisement
Add Comment
Please, Sign In to add comment