On this page
page_attributes_meta_box( WP_Post $post )
Displays page attributes form fields.
Parameters
$postWP_Post Required-
Current post object.
Source
File: wp-admin/includes/meta-boxes.php. View all references
function page_attributes_meta_box( $post ) {
if ( is_post_type_hierarchical( $post->post_type ) ) :
$dropdown_args = array(
'post_type' => $post->post_type,
'exclude_tree' => $post->ID,
'selected' => $post->post_parent,
'name' => 'parent_id',
'show_option_none' => __( '(no parent)' ),
'sort_column' => 'menu_order, post_title',
'echo' => 0,
);
/**
* Filters the arguments used to generate a Pages drop-down element.
*
* @since 3.3.0
*
* @see wp_dropdown_pages()
*
* @param array $dropdown_args Array of arguments used to generate the pages drop-down.
* @param WP_Post $post The current post.
*/
$dropdown_args = apply_filters( 'page_attributes_dropdown_pages_args', $dropdown_args, $post );
$pages = wp_dropdown_pages( $dropdown_args );
if ( ! empty( $pages ) ) :
?>
<p class="post-attributes-label-wrapper parent-id-label-wrapper"><label class="post-attributes-label" for="parent_id"><?php _e( 'Parent' ); ?></label></p>
<?php echo $pages; ?>
<?php
endif; // End empty pages check.
endif; // End hierarchical check.
if ( count( get_page_templates( $post ) ) > 0 && get_option( 'page_for_posts' ) != $post->ID ) :
$template = ! empty( $post->page_template ) ? $post->page_template : false;
?>
<p class="post-attributes-label-wrapper page-template-label-wrapper"><label class="post-attributes-label" for="page_template"><?php _e( 'Template' ); ?></label>
<?php
/**
* Fires immediately after the label inside the 'Template' section
* of the 'Page Attributes' meta box.
*
* @since 4.4.0
*
* @param string|false $template The template used for the current post.
* @param WP_Post $post The current post.
*/
do_action( 'page_attributes_meta_box_template', $template, $post );
?>
</p>
<select name="page_template" id="page_template">
<?php
/**
* Filters the title of the default page template displayed in the drop-down.
*
* @since 4.1.0
*
* @param string $label The display value for the default page template title.
* @param string $context Where the option label is displayed. Possible values
* include 'meta-box' or 'quick-edit'.
*/
$default_title = apply_filters( 'default_page_template_title', __( 'Default template' ), 'meta-box' );
?>
<option value="default"><?php echo esc_html( $default_title ); ?></option>
<?php page_template_dropdown( $template, $post->post_type ); ?>
</select>
<?php endif; ?>
<?php if ( post_type_supports( $post->post_type, 'page-attributes' ) ) : ?>
<p class="post-attributes-label-wrapper menu-order-label-wrapper"><label class="post-attributes-label" for="menu_order"><?php _e( 'Order' ); ?></label></p>
<input name="menu_order" type="text" size="4" id="menu_order" value="<?php echo esc_attr( $post->menu_order ); ?>" />
<?php
/**
* Fires before the help hint text in the 'Page Attributes' meta box.
*
* @since 4.9.0
*
* @param WP_Post $post The current post.
*/
do_action( 'page_attributes_misc_attributes', $post );
?>
<?php if ( 'page' === $post->post_type && get_current_screen()->get_help_tabs() ) : ?>
<p class="post-attributes-help-text"><?php _e( 'Need help? Use the Help tab above the screen title.' ); ?></p>
<?php
endif;
endif;
}
Hooks
- apply_filters( 'default_page_template_title',
string $label ,string $context ) -
Filters the title of the default page template displayed in the drop-down.
- apply_filters( 'page_attributes_dropdown_pages_args',
array $dropdown_args ,WP_Post $post ) -
Filters the arguments used to generate a Pages drop-down element.
- do_action( 'page_attributes_meta_box_template',
string|false $template ,WP_Post $post ) -
Fires immediately after the label inside the ‘Template’ section of the ‘Page Attributes’ meta box.
- do_action( 'page_attributes_misc_attributes',
WP_Post $post ) -
Fires before the help hint text in the ‘Page Attributes’ meta box.
Related
Uses
| Uses | Description |
|---|---|
| get_page_templates() wp-admin/includes/theme.php | Gets the page templates available in this theme. |
| WP_Screen::get_help_tabs() wp-admin/includes/class-wp-screen.php | Gets the help tabs registered for the screen. |
| get_current_screen() wp-admin/includes/screen.php | Get the current screen object |
| page_template_dropdown() wp-admin/includes/template.php | Prints out option HTML elements for the page templates drop-down. |
| wp_dropdown_pages() wp-includes/post-template.php | Retrieves or displays a list of pages as a dropdown (select list). |
| post_type_supports() wp-includes/post.php | Checks a post type’s support for a given feature. |
| is_post_type_hierarchical() wp-includes/post.php | Determines whether the post type is hierarchical. |
| __() wp-includes/l10n.php | Retrieves the translation of $text. |
| _e() wp-includes/l10n.php | Displays translated text. |
| esc_html() wp-includes/formatting.php | Escaping for HTML blocks. |
| esc_attr() wp-includes/formatting.php | Escaping for HTML attributes. |
| apply_filters() wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. |
| do_action() wp-includes/plugin.php | Calls the callback functions that have been added to an action hook. |
| get_option() wp-includes/option.php | Retrieves an option value based on an option name. |
Changelog
| Version | Description |
|---|---|
| 2.7.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/page_attributes_meta_box