Make WordPress Core

Opened 7 years ago

Closed 22 months ago

#40807 closed enhancement (maybelater)

Starter content: Allow for setting a "parent" for pages (and other hierarchical CPTs)

Reported by: webmandesign's profile webmandesign Owned by: westonruter's profile westonruter
Milestone: Priority: normal
Severity: normal Version: 4.7
Component: Customize Keywords: has-patch has-unit-tests
Focuses: Cc:

Description (last modified by westonruter)

From what I can see in get_theme_starter_content() function, it only allows for specific fields to be set for posts: post_type, post_title, post_excerpt, post_name, post_content, menu_order, comment_status, thumbnail and template.

I would like to propose adding a parent field in there too for hierarchical post types, such as Pages.

That way we can also create child pages (or sub-pages) in starter content, such as:

$starter_content = array(

  'posts' => array(

    'contact' => array(
      'template' => 'page-templates/list-of-child-pages.php',

    'contact-dublin' => array(
      'post_type'    => 'page',
      'post_title'   => 'Dublin Office Contact',
      'post_content' => 'Page content here...',
      'parent'       => '{{contact}}', // <-- Here's the magic:
                                       //     Making this a child page of our "Contact" page.



Thanks for consideration!

Attachments (4)

40807.patch (3.9 KB) - added by birgire 7 years ago.
40807.2.patch (4.5 KB) - added by birgire 7 years ago.
40807.3.diff (4.4 KB) - added by westonruter 7 years ago.
40807.4.diff (4.5 KB) - added by birgire 7 years ago.

Download all attachments as: .zip

Change History (19)

#1 @westonruter
7 years ago

  • Description modified (diff)
  • Keywords needs-patch added
  • Milestone changed from Awaiting Review to Future Release
  • Version changed from trunk to 4.7

Good call. Yes, this makes great sense.

7 years ago

#2 @birgire
7 years ago

  • Keywords has-patch has-unit-tests added; needs-patch removed

Sounds like a good idea.

Here's a first attempt to support setting a parent post symbol.

In 40807.patch

  • Translate the parent post symbol to an ID and assign it to the post_parent field with wp_update_post()
  • Uses the parent key for symbols, to not confuse it with post_parent that only supports an integer value.
  • Includes a test, based on the existing one for starter-content

7 years ago

#3 @birgire
7 years ago

In 40807.2.patch

  • Added a deeper test config tree.
  • Added a failing (non-existing) parent post symbol, in the test config.
  • Use get_post_field() to get the post_parent field.

To consider:

  • Add a hierarchical post type restriction on posts using the parent
  • Add a same parent/child post type restriction on posts using the parent

Last edited 7 years ago by birgire (previous) (diff)

#4 @westonruter
7 years ago

  • Milestone changed from Future Release to 4.9
  • Owner set to westonruter
  • Status changed from new to reviewing

#5 @westonruter
7 years ago

@birgire patch is looking good! I don't think we need to worry about restricting which post types can have children. I think this hierarchical property is really more for the sake of the UI than a restriction on the data model. After all, an attachment post can have parent even though it isn't hierarchical.

See my changes for what needed to be done to apply WordPress-Coding-Standards. It was mostly whitespace changes; see diff without.

A build is running now:

While this was marked as an enhancement, I'm inclined to include it in 4.9 as it is closely related to #39254.

Last edited 7 years ago by westonruter (previous) (diff)

#6 @birgire
7 years ago

Thank you @westonruter for the whitespace cleanup and the other info.

I will consult the phpcs --standard=WordPress ... when writing patches from now on ;-)

I agree with your reasoning regarding the consideration of the two restrictions.

7 years ago

#7 @birgire
7 years ago

It looks like I forgot the {{...}} syntax, in the previous patch.

In 40807.4.diff we assume the parent reference to be like:

'animal' => array(
    'post_type'  => 'page',
    'post_title' => 'Animal',
'fish'   => array(
    'post_type'  => 'page',
    'post_title' => 'Fish',
    'parent'     => '{{animal}}',

This ticket was mentioned in Slack in #core by melchoyce. View the logs.

7 years ago

#9 @westonruter
7 years ago

  • Milestone changed from 4.9 to 4.9.1

Punting this to the next minor release along with #39254, due to the number of outstanding tickets and lack of availability to focus on this.

#10 @johnbillion
7 years ago

  • Milestone changed from 4.9.1 to 5.0

#11 @benoitchantre
6 years ago

I haven't tested the patch, but I would like to mention that it would be great to support sub menu items.

#12 @johnbillion
6 years ago

  • Milestone changed from 5.0 to 5.1

#13 @pento
5 years ago

  • Milestone changed from 5.1 to Future Release

It'd be a good to show a practical use for this.

#14 @webmandesign
5 years ago

@pento Practical use example:
In my Reykjavik theme I provide a special page template that displays a list of child pages. There is no way I can build a starter content to show this feature now.

Here is an example of how a child pages list page template look like: (scroll down to see the list of child pages for that particular parent page).

Last edited 5 years ago by webmandesign (previous) (diff)

#15 @westonruter
22 months ago

  • Milestone Future Release deleted
  • Resolution set to maybelater
  • Status changed from reviewing to closed

New feature development is being directed toward the Site Editor, so I'm closing this.

Note: See TracTickets for help on using tickets.