Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
320 views
in Technique[技术] by (71.8m points)

Creating a multiple subpages in Wordpress with the same content and template as the parent

Is there a way to generate multiple new pages in wordpress with the same template, content and everything else except page name in Wordpress. The names of the new pages will be from a list of about 300 cities.

I found a plugin called BulkPress where i can insert the list and it generates the pages but with the default template and no content.

EDIT: Sorry i missed one important thing! All the pages need to be subpages of one already made parent page and the template and content needs to be copied from that parent!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You could create this with programmatically. Put below code in your active template functions.php. It will insert 300 pages.

wp_insert_post( array $postarr, bool $wp_error = false, bool $fire_after_hooks = true )

e.g.,

foreach($i=1;$i<=300;$i++){
    $my_post = array(
      'post_title'    => wp_strip_all_tags( "Your post Title" ),
      'post_type'      => 'page',
      'post_content'  => "Post Content Goes here",
      'post_status'   => 'publish',
      'post_author'   => 1,
      'page_template'  => 'template-blog.php',
      'post_author'    => get_user_by( 'id', 1 )->user_id,
    );
// Insert the post into the database
wp_insert_post( $my_post );

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...