Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Here are two codes I am trying to mix/ish
- // This code will make pages (as many as I need) when you active a theme in wordpress
- // How ever, it does NOT set a template to use OR Content
- function create_initial_pages() {
- $pages = array(
- 'page1' => 'Page 1',
- 'page2' => 'Page 2',
- 'page3' => 'Page 3',
- 'page4' => 'Page 4'
- );
- foreach($pages as $page_url => $page_title) {
- $id = get_page_by_title($page_title);
- $page = array(
- 'post_type' => 'page',
- 'post_name' => $page_url,
- 'post_title' => $page_title,
- 'post_status' => 'publish',
- 'post_author' => 1,
- 'post_parent' => ''
- );
- if (!isset($id)) wp_insert_post($page);
- };
- }
- // This is code I have will only make ONE page but it will set some content and a template
- // that will be used when making the page...
- if (isset($_GET['activated']) && is_admin()){
- $new_page_title = 'Sitemap';
- $new_page_content = ' ';
- $new_page_template = 'sitemap.php'; //ex. template-custom.php. Leave blank if you don't want a custom page template.
- //don't change the code bellow, unless you know what you're doing
- $page_check = get_page_by_title($new_page_title);
- $new_page = array(
- 'post_type' => 'page',
- 'post_title' => $new_page_title,
- 'post_content' => $new_page_content,
- 'post_status' => 'publish',
- 'post_author' => 1,
- );
- if(!isset($page_check->ID)){
- $new_page_id = wp_insert_post($new_page);
- if(!empty($new_page_template)){
- update_post_meta($new_page_id, '_wp_page_template', $new_page_template);
- }
- }
- }
- /// Both codes work, but I need code that will make more than one page and set everything. . .
- /// I think this would word if I were to use a 2 dimensional array but my coding is not that good.. . .
- // Here is a bad a temp to show what I am trying to do with code. . .
- // I did comment out my bad coding to make it so you could see it
- if (isset($_GET['activated']) && is_admin()){
- add_action('init', 'create_initial_pages');
- }
- function create_initial_pages() {
- $pages = array(
- 'page1' => 'Page 1', // => 'Content Coming Soon', => 'custom-file.php',
- 'page2' => 'Page 2', // => 'Content Coming Soon', => 'custom-file.php',
- 'page3' => 'Page 3', // => 'Content Coming Soon', => 'custom-file.php',
- 'page4' => 'Page 4' // => 'Content Coming Soon', => 'custom-file.php',
- );
- foreach($pages as $page_url => $page_title /** => $coming_content => $cuustom_file **/ ) {
- $id = get_page_by_title($page_title);
- $page = array(
- 'post_type' => 'page',
- 'post_name' => $page_url,
- 'post_title' => $page_title,
- 'post_content' => $page_content,
- 'post_status' => 'publish',
- 'post_author' => 1,
- 'post_parent' => ''
- );
- if (!isset($id)) wp_insert_post($page);
- if(!isset($id->ID)){
- $new_page_id = wp_insert_post($new);
- if(!empty($cuustom_file)){
- update_post_meta($new_page_id, '_wp_page_template', $cuustom_file);
- }
- }
- };
- }
- $page_check = get_page_by_title($new_page_title);
Advertisement
Add Comment
Please, Sign In to add comment