Eine auf WordPress spezialiserte Suchmaschine für Entwickler und Theme-Autoren



parent_dropdown ›

Seit1.5.0
Veraltetn/v
parent_dropdown ( $default = 0, $parent = 0, $level = 0, $post = null )
Parameter: (4)
  • (int) $default Optional. The default page ID to be pre-selected. Default 0.
    Erforderlich: Nein
    Standard:
  • (int) $parent Optional. The parent page ID. Default 0.
    Erforderlich: Nein
    Standard:
  • (int) $level Optional. Page depth level. Default 0.
    Erforderlich: Nein
    Standard:
  • (int|WP_Post) $post Post ID or WP_Post object.
    Erforderlich: Nein
    Standard: null
Gibt zurück:
  • (null|false) Boolean False if page has no children, otherwise print out html elements
Definiert in:
Codex:
Changelog:
  • 4.4.0 ` $post` argument was added.

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



Quellcode

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;
	}
}