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 {
19 * @see Walker::$tree_type
23 public $tree_type = 'page';
26 * @see Walker::$db_fields
31 public $db_fields = array ('parent' => 'post_parent', 'id' => 'ID');
34 * @see Walker::start_el()
37 * @param string $output Passed by reference. Used to append additional content.
38 * @param object $page Page data object.
39 * @param int $depth Depth of page in reference to parent pages. Used for padding.
40 * @param array $args Uses 'selected' argument for selected page to set selected HTML attribute for option
41 * element. Uses 'value_field' argument to fill "value" attribute. See {@see wp_dropdown_pages()}.
44 public function start_el( &$output, $page, $depth = 0, $args = array(), $id = 0 ) {
45 $pad = str_repeat(' ', $depth * 3);
47 if ( ! isset( $args['value_field'] ) || ! isset( $page->{$args['value_field']} ) ) {
48 $args['value_field'] = 'ID';
51 $output .= "\t<option class=\"level-$depth\" value=\"" . esc_attr( $page->{$args['value_field']} ) . "\"";
52 if ( $page->ID == $args['selected'] )
53 $output .= ' selected="selected"';
56 $title = $page->post_title;
57 if ( '' === $title ) {
58 /* translators: %d: ID of a post */
59 $title = sprintf( __( '#%d (no title)' ), $page->ID );
63 * Filter the page title when creating an HTML drop-down list of pages.
67 * @param string $title Page title.
68 * @param object $page Page data object.
70 $title = apply_filters( 'list_pages', $title, $page );
71 $output .= $pad . esc_html( $title );
72 $output .= "</option>\n";