3 * Post API: Walker_PageDropdown class
11 * Core class used to create an HTML drop-down list of pages.
17 class Walker_PageDropdown extends Walker {
20 * What the class handles.
26 * @see Walker::$tree_type
28 public $tree_type = 'page';
31 * Database fields to use.
37 * @see Walker::$db_fields
40 public $db_fields = array( 'parent' => 'post_parent', 'id' => 'ID' );
43 * Starts the element output.
48 * @see Walker::start_el()
50 * @param string $output Used to append additional content. Passed by reference.
51 * @param WP_Post $page Page data object.
52 * @param int $depth Optional. Depth of page in reference to parent pages. Used for padding.
54 * @param array $args Optional. Uses 'selected' argument for selected page to set selected HTML
55 * attribute for option element. Uses 'value_field' argument to fill "value"
56 * attribute. See wp_dropdown_pages(). Default empty array.
57 * @param int $id Optional. ID of the current page. Default 0 (unused).
59 public function start_el( &$output, $page, $depth = 0, $args = array(), $id = 0 ) {
60 $pad = str_repeat(' ', $depth * 3);
62 if ( ! isset( $args['value_field'] ) || ! isset( $page->{$args['value_field']} ) ) {
63 $args['value_field'] = 'ID';
66 $output .= "\t<option class=\"level-$depth\" value=\"" . esc_attr( $page->{$args['value_field']} ) . "\"";
67 if ( $page->ID == $args['selected'] )
68 $output .= ' selected="selected"';
71 $title = $page->post_title;
72 if ( '' === $title ) {
73 /* translators: %d: ID of a post */
74 $title = sprintf( __( '#%d (no title)' ), $page->ID );
78 * Filters the page title when creating an HTML drop-down list of pages.
82 * @param string $title Page title.
83 * @param object $page Page data object.
85 $title = apply_filters( 'list_pages', $title, $page );
87 $output .= $pad . esc_html( $title );
88 $output .= "</option>\n";