Walker_Page

Core walker class used to create an HTML list of pages.

Defined (1)

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

/wp-includes/class-walker-page.php  
  1. class Walker_Page 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 private 
  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. * Outputs the beginning of the current level in the tree before elements are output. 
  24. * @since 2.1.0 
  25. * @access public 
  26. * @see Walker::start_lvl() 
  27. * @param string $output Passed by reference. Used to append additional content. 
  28. * @param int $depth Optional. Depth of page. Used for padding. Default 0. 
  29. * @param array $args Optional. Arguments for outputing the next level. 
  30. * Default empty array. 
  31. */ 
  32. public function start_lvl( &$output, $depth = 0, $args = array() ) { 
  33. $indent = str_repeat("\t", $depth); 
  34. $output .= "\n$indent<ul class='children'>\n"; 
  35.  
  36. /** 
  37. * Outputs the end of the current level in the tree after elements are output. 
  38. * @since 2.1.0 
  39. * @access public 
  40. * @see Walker::end_lvl() 
  41. * @param string $output Passed by reference. Used to append additional content. 
  42. * @param int $depth Optional. Depth of page. Used for padding. Default 0. 
  43. * @param array $args Optional. Arguments for outputting the end of the current level. 
  44. * Default empty array. 
  45. */ 
  46. public function end_lvl( &$output, $depth = 0, $args = array() ) { 
  47. $indent = str_repeat("\t", $depth); 
  48. $output .= "$indent</ul>\n"; 
  49.  
  50. /** 
  51. * Outputs the beginning of the current element in the tree. 
  52. * @see Walker::start_el() 
  53. * @since 2.1.0 
  54. * @access public 
  55. * @param string $output Used to append additional content. Passed by reference. 
  56. * @param WP_Post $page Page data object. 
  57. * @param int $depth Optional. Depth of page. Used for padding. Default 0. 
  58. * @param array $args Optional. Array of arguments. Default empty array. 
  59. * @param int $current_page Optional. Page ID. Default 0. 
  60. */ 
  61. public function start_el( &$output, $page, $depth = 0, $args = array(), $current_page = 0 ) { 
  62. if ( $depth ) { 
  63. $indent = str_repeat( "\t", $depth ); 
  64. } else { 
  65. $indent = ''; 
  66.  
  67. $css_class = array( 'page_item', 'page-item-' . $page->ID ); 
  68.  
  69. if ( isset( $args['pages_with_children'][ $page->ID ] ) ) { 
  70. $css_class[] = 'page_item_has_children'; 
  71.  
  72. if ( ! empty( $current_page ) ) { 
  73. $_current_page = get_post( $current_page ); 
  74. if ( $_current_page && in_array( $page->ID, $_current_page->ancestors ) ) { 
  75. $css_class[] = 'current_page_ancestor'; 
  76. if ( $page->ID == $current_page ) { 
  77. $css_class[] = 'current_page_item'; 
  78. } elseif ( $_current_page && $page->ID == $_current_page->post_parent ) { 
  79. $css_class[] = 'current_page_parent'; 
  80. } elseif ( $page->ID == get_option('page_for_posts') ) { 
  81. $css_class[] = 'current_page_parent'; 
  82.  
  83. /** 
  84. * Filters the list of CSS classes to include with each page item in the list. 
  85. * @since 2.8.0 
  86. * @see wp_list_pages() 
  87. * @param array $css_class An array of CSS classes to be applied 
  88. * to each list item. 
  89. * @param WP_Post $page Page data object. 
  90. * @param int $depth Depth of page, used for padding. 
  91. * @param array $args An array of arguments. 
  92. * @param int $current_page ID of the current page. 
  93. */ 
  94. $css_classes = implode( ' ', apply_filters( 'page_css_class', $css_class, $page, $depth, $args, $current_page ) ); 
  95.  
  96. if ( '' === $page->post_title ) { 
  97. /** translators: %d: ID of a post */ 
  98. $page->post_title = sprintf( __( '#%d (no title)' ), $page->ID ); 
  99.  
  100. $args['link_before'] = empty( $args['link_before'] ) ? '' : $args['link_before']; 
  101. $args['link_after'] = empty( $args['link_after'] ) ? '' : $args['link_after']; 
  102.  
  103. $output .= $indent . sprintf( 
  104. '<li class="%s"><a href="%s">%s%s%s</a>',  
  105. $css_classes,  
  106. get_permalink( $page->ID ),  
  107. $args['link_before'],  
  108. /** This filter is documented in wp-includes/post-template.php */ 
  109. apply_filters( 'the_title', $page->post_title, $page->ID ),  
  110. $args['link_after'] 
  111. ); 
  112.  
  113. if ( ! empty( $args['show_date'] ) ) { 
  114. if ( 'modified' == $args['show_date'] ) { 
  115. $time = $page->post_modified; 
  116. } else { 
  117. $time = $page->post_date; 
  118.  
  119. $date_format = empty( $args['date_format'] ) ? '' : $args['date_format']; 
  120. $output .= " " . mysql2date( $date_format, $time ); 
  121.  
  122. /** 
  123. * Outputs the end of the current element in the tree. 
  124. * @since 2.1.0 
  125. * @access public 
  126. * @see Walker::end_el() 
  127. * @param string $output Used to append additional content. Passed by reference. 
  128. * @param WP_Post $page Page data object. Not used. 
  129. * @param int $depth Optional. Depth of page. Default 0 (unused). 
  130. * @param array $args Optional. Array of arguments. Default empty array. 
  131. */ 
  132. public function end_el( &$output, $page, $depth = 0, $args = array() ) { 
  133. $output .= "</li>\n"; 
  134.