Changeset 6652
- Timestamp:
- 02/16/2018 02:22:58 AM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-main/functions.php
r6583 r6652 87 87 88 88 /** 89 * Adds child-page-specific template name to page template hierarchy. 90 * 91 * @param array $templates A list of template candidates, in descending order of priority. 92 * @return array List of filtered template candidates. 93 */ 94 function child_page_templates( $templates ) { 95 $page = get_queried_object(); 96 97 if ( $page->post_parent ) { 98 $parent = get_post( $page->post_parent ); 99 100 // We want it before page-{page_name}.php but after {Page Template}.php. 101 $page_name_index = array_search( "page-{$page->post_name}.php", $templates ); 102 $top = array_slice( $templates, 0, $page_name_index ); 103 $bottom = array_slice( $templates, $page_name_index ); 104 105 $templates = array_merge( $top, ["page-{$parent->post_name}-{$page->post_name}.php"], $bottom ); 106 } 107 108 return $templates; 109 } 110 add_filter( 'page_template_hierarchy', __NAMESPACE__ . '\child_page_templates' ); 111 112 /** 89 113 * Custom template tags. 90 114 */
Note: See TracChangeset
for help on using the changeset viewer.