Walker_PageDropdown

Core class used to create an HTML drop-down list of pages.

Defined (1)

The class is defined in the following location(s).

/wp-includes/class-walker-page-dropdown.php  
  1. class Walker_PageDropdown extends Walker { 
  2.  
  3. /** 
  4. * What the class handles. 
  5. * @since 2.1.0 
  6. * @access public 
  7. * @var string 
  8. * @see Walker::$tree_type 
  9. */ 
  10. public $tree_type = 'page'; 
  11.  
  12. /** 
  13. * Database fields to use. 
  14. * @since 2.1.0 
  15. * @access public 
  16. * @var array 
  17. * @see Walker::$db_fields 
  18. * @todo Decouple this 
  19. */ 
  20. public $db_fields = array( 'parent' => 'post_parent', 'id' => 'ID' ); 
  21.  
  22. /** 
  23. * Starts the element output. 
  24. * @since 2.1.0 
  25. * @access public 
  26. * @see Walker::start_el() 
  27. * @param string $output Used to append additional content. Passed by reference. 
  28. * @param WP_Post $page Page data object. 
  29. * @param int $depth Optional. Depth of page in reference to parent pages. Used for padding. 
  30. * Default 0. 
  31. * @param array $args Optional. Uses 'selected' argument for selected page to set selected HTML 
  32. * attribute for option element. Uses 'value_field' argument to fill "value" 
  33. * attribute. See wp_dropdown_pages(). Default empty array. 
  34. * @param int $id Optional. ID of the current page. Default 0 (unused). 
  35. */ 
  36. public function start_el( &$output, $page, $depth = 0, $args = array(), $id = 0 ) { 
  37. $pad = str_repeat(' ', $depth * 3); 
  38.  
  39. if ( ! isset( $args['value_field'] ) || ! isset( $page->{$args['value_field']} ) ) { 
  40. $args['value_field'] = 'ID'; 
  41.  
  42. $output .= "\t<option class=\"level-$depth\" value=\"" . esc_attr( $page->{$args['value_field']} ) . "\""; 
  43. if ( $page->ID == $args['selected'] ) 
  44. $output .= ' selected="selected"'; 
  45. $output .= '>'; 
  46.  
  47. $title = $page->post_title; 
  48. if ( '' === $title ) { 
  49. /** translators: %d: ID of a post */ 
  50. $title = sprintf( __( '#%d (no title)' ), $page->ID ); 
  51.  
  52. /** 
  53. * Filters the page title when creating an HTML drop-down list of pages. 
  54. * @since 3.1.0 
  55. * @param string $title Page title. 
  56. * @param object $page Page data object. 
  57. */ 
  58. $title = apply_filters( 'list_pages', $title, $page ); 
  59.  
  60. $output .= $pad . esc_html( $title ); 
  61. $output .= "</option>\n";