parent_dropdown() - WordPress 函数参考中文文档

返回介绍

parent_dropdown()

发布于 2017-09-11 字数2744 浏览 577 评论 0

parent_dropdown( int $default,  int $parent,  int $level,  int|WP_Post $post = null )

Print out option HTML elements for the page parents drop-down.


描述


参数

$default

(int)
(Optional)
The default page ID to be pre-selected. Default 0.

$parent

(int)
(Optional)
The parent page ID. Default 0.

$level

(int)
(Optional)
Page depth level. Default 0.

$post

(int|WP_Post)
(Optional)
Post ID or WP_Post object.

Default value: null


返回值

(null|false) Boolean False if page has no children, otherwise print out html elements


源代码

File: wp-admin/includes/template.php

function parent_dropdown( $default = 0, $parent = 0, $level = 0, $post = null ) {
	global $wpdb;
	$post = get_post( $post );
	$items = $wpdb->get_results( $wpdb->prepare("SELECT ID, post_parent, post_title FROM $wpdb->posts WHERE post_parent = %d AND post_type = 'page' ORDER BY menu_order", $parent) );

	if ( $items ) {
		foreach ( $items as $item ) {
			// A page cannot be its own parent.
			if ( $post && $post->ID && $item->ID == $post->ID )
				continue;

			$pad = str_repeat( ' ', $level * 3 );
			$selected = selected( $default, $item->ID, false );

			echo "\n\t<option class='level-$level' value='$item->ID' $selected>$pad " . esc_html($item->post_title) . "</option>";
			parent_dropdown( $default, $item->ID, $level +1 );
		}
	} else {
		return false;
	}
}

更新日志

Version 描述
4.4.0 $post argument was added.
1.5.0 Introduced.

相关函数

Uses

  • wp-admin/includes/template.php:
    parent_dropdown()
  • wp-includes/formatting.php:
    esc_html()
  • wp-includes/general-template.php:
    selected()
  • wp-includes/post.php:
    get_post()
  • wp-includes/wp-db.php:
    wpdb::get_results()
  • wp-includes/wp-db.php:
    wpdb::prepare()
  • Show 1 more use
    Hide more uses


Used By

  • wp-admin/includes/template.php:
    parent_dropdown()

User Contributed Notes

上一篇:paginate_links()

下一篇:parent_post_rel_link()

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

目前还没有任何评论,快来抢沙发吧!