Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

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