Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.38 KB | None | 0 0
  1. /модернизация меню
  2. //
  3. //
  4. class Walker_Left_menu extends Walker_Category {
  5.  
  6. public function start_lvl( &$output, $depth = +1, $args = array() ) {
  7. if ( 'list' != $args['style'] ) {
  8. return;
  9. }
  10.  
  11. $indent = str_repeat( "\t", $depth );
  12. $output .= "$indent<input type=\"checkbox\" class=\"subCat\" id=\"$depth\" checked=\"checked\" /><label class=\"chka\" for=\"$depth\"></label><ul style=\"display:none\">\n";
  13. }
  14.  
  15. /**
  16. * Ends the list of after the elements are added.
  17. *
  18. * @since 2.1.0
  19. *
  20. * @see Walker::end_lvl()
  21. *
  22. * @param string $output Used to append additional content. Passed by reference.
  23. * @param int $depth Optional. Depth of category. Used for tab indentation. Default 0.
  24. * @param array $args Optional. An array of arguments. Will only append content if style argument
  25. * value is 'list'. See wp_list_categories(). Default empty array.
  26. */
  27. public function end_lvl( &$output, $depth = 0, $args = array() ) {
  28. if ( 'list' != $args['style'] ) {
  29. return;
  30. }
  31.  
  32. $indent = str_repeat( "\t", $depth );
  33. $output .= "$indent</ul>\n";
  34. }
  35.  
  36. public function start_el( &$output, $category, $depth = 0, $args = array(), $id = 0 ) {
  37. /** This filter is documented in wp-includes/category-template.php */
  38. $cat_name = apply_filters(
  39. 'list_cats',
  40. esc_attr( $category->name ),
  41. $category
  42. );
  43.  
  44. // Don't generate an element if the category name is empty.
  45. if ( '' === $cat_name ) {
  46. return;
  47. }
  48.  
  49. $atts = array();
  50. $atts['href'] = get_term_link( $category );
  51.  
  52. if ( $args['use_desc_for_title'] && ! empty( $category->description ) ) {
  53. /**
  54. * Filters the category description for display.
  55. *
  56. * @since 1.2.0
  57. *
  58. * @param string $description Category description.
  59. * @param object $category Category object.
  60. */
  61. $atts['title'] = strip_tags( apply_filters( 'category_description', $category->description, $category ) );
  62. }
  63.  
  64. /**
  65. * Filters the HTML attributes applied to a category list item's anchor element.
  66. *
  67. * @since 5.2.0
  68. *
  69. * @param array $atts {
  70. * The HTML attributes applied to the list item's `<a>` element, empty strings are ignored.
  71. *
  72. * @type string $href The href attribute.
  73. * @type string $title The title attribute.
  74. * }
  75. * @param WP_Term $category Term data object.
  76. * @param int $depth Depth of category, used for padding.
  77. * @param array $args An array of arguments.
  78. * @param int $id ID of the current category.
  79. */
  80. $atts = apply_filters( 'category_list_link_attributes', $atts, $category, $depth, $args, $id );
  81.  
  82. $attributes = '';
  83. foreach ( $atts as $attr => $value ) {
  84. if ( ! empty( $value ) ) {
  85. $value = ( 'href' === $attr ) ? esc_url( $value ) : esc_attr( $value );
  86. $attributes .= ' ' . $attr . '="' . $value . '"';
  87. }
  88. }
  89.  
  90. $link = sprintf(
  91. '<a%s>%s</a>',
  92. $attributes,
  93. $cat_name
  94. );
  95.  
  96. if ( ! empty( $args['feed_image'] ) || ! empty( $args['feed'] ) ) {
  97. $link .= ' ';
  98.  
  99. if ( empty( $args['feed_image'] ) ) {
  100. $link .= '(';
  101. }
  102.  
  103. $link .= '<a href="' . esc_url( get_term_feed_link( $category->term_id, $category->taxonomy, $args['feed_type'] ) ) . '"';
  104.  
  105. if ( empty( $args['feed'] ) ) {
  106. /* translators: %s: category name */
  107. $alt = ' alt="' . sprintf( __( 'Feed for all posts filed under %s' ), $cat_name ) . '"';
  108. } else {
  109. $alt = ' alt="' . $args['feed'] . '"';
  110. $name = $args['feed'];
  111. $link .= empty( $args['title'] ) ? '' : $args['title'];
  112. }
  113.  
  114. $link .= '>';
  115.  
  116. if ( empty( $args['feed_image'] ) ) {
  117. $link .= $name;
  118. } else {
  119. $link .= "<img src='" . esc_url( $args['feed_image'] ) . "'$alt" . ' />';
  120. }
  121. $link .= '</a>';
  122.  
  123. if ( empty( $args['feed_image'] ) ) {
  124. $link .= ')';
  125. }
  126. }
  127.  
  128. if ( ! empty( $args['show_count'] ) ) {
  129. $link .= ' (' . number_format_i18n( $category->count ) . ')';
  130. }
  131. if ( 'list' == $args['style'] ) {
  132. $output .= "\t<li";
  133. $css_classes = array(
  134. '',
  135. );
  136.  
  137. if ( ! empty( $args['current_category'] ) ) {
  138. // 'current_category' can be an array, so we use `get_terms()`.
  139. $_current_terms = get_terms(
  140. $category->taxonomy,
  141. array(
  142. 'include' => $args['current_category'],
  143. 'hide_empty' => false,
  144. )
  145. );
  146.  
  147. foreach ( $_current_terms as $_current_term ) {
  148. if ( $category->term_id == $_current_term->term_id ) {
  149. $css_classes[] = 'current-cat';
  150. } elseif ( $category->term_id == $_current_term->parent ) {
  151. $css_classes[] = 'current-cat-parent';
  152. }
  153. while ( $_current_term->parent ) {
  154. if ( $category->term_id == $_current_term->parent ) {
  155. $css_classes[] = 'current-cat-ancestor';
  156. break;
  157. }
  158. $_current_term = get_term( $_current_term->parent, $category->taxonomy );
  159. }
  160. }
  161. }
  162.  
  163. /**
  164. * Filters the list of CSS classes to include with each category in the list.
  165. *
  166. * @since 4.2.0
  167. *
  168. * @see wp_list_categories()
  169. *
  170. * @param array $css_classes An array of CSS classes to be applied to each list item.
  171. * @param object $category Category data object.
  172. * @param int $depth Depth of page, used for padding.
  173. * @param array $args An array of wp_list_categories() arguments.
  174. */
  175. $css_classes = implode( ' ', apply_filters( 'category_css_class', $css_classes, $category, $depth, $args ) );
  176. $css_classes = $css_classes ? ' class="' . esc_attr( $css_classes ) . '"' : '';
  177.  
  178. $output .= $css_classes;
  179. $output .= ">$link\n";
  180. } elseif ( isset( $args['separator'] ) ) {
  181. $output .= "\t$link" . $args['separator'] . "\n";
  182. } else {
  183. $output .= "\t$link<br />\n";
  184. }
  185. }
  186.  
  187. /**
  188. * Ends the element output, if needed.
  189. *
  190. * @since 2.1.0
  191. *
  192. * @see Walker::end_el()
  193. *
  194. * @param string $output Used to append additional content (passed by reference).
  195. * @param object $page Not used.
  196. * @param int $depth Optional. Depth of category. Not used.
  197. * @param array $args Optional. An array of arguments. Only uses 'list' for whether should append
  198. * to output. See wp_list_categories(). Default empty array.
  199. */
  200. public function end_el( &$output, $page, $depth = 0, $args = array() ) {
  201. if ( 'list' != $args['style'] ) {
  202. return;
  203. }
  204.  
  205. $output .= "</li>\n";
  206. }
  207.  
  208. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement