Advertisement
campusboy

Евгений

Jul 13th, 2018
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.57 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Описание функции
  4.  * @param array $atts
  5.  * @return string
  6.  */
  7. function subcats_func( $atts ) {
  8.   $data = '';
  9.  
  10.   // Если не рубрика - обрывает выполнение функции
  11.   if ( ! is_category() || ! is_product_category() ) {
  12.     return $data;
  13.   }
  14.  
  15.   $term = get_queried_object();
  16.  
  17.   // Объединяет указанные атрибуты (параметры) шоткода с известными атрибутами (из белого списка)
  18.   $atts = shortcode_atts( array(
  19.     'cat_id' => $term->term_id,
  20.   ), $atts );
  21.  
  22.   // Получает рубрики
  23.   $cats = get_categories( [
  24.     'parent'      => $atts[ 'cat_id' ],
  25.     'hide_empty'  => 0,
  26.     'taxonomy'    => $term->taxonomy
  27.   ] );
  28.  
  29.   if ( $cats ) {
  30.     $cat_links = '';
  31.     foreach ( $cats as $cat ) {
  32.       $cat_links .= sprintf( ' <a class="n-cat" href="%s">%s</a> ', get_category_link( $cat->term_id ), $cat->cat_name );
  33.     }
  34.    
  35.     $data = sprintf( '<div class="navy-cat">%s</div>', $cat_links );
  36.   }
  37.  
  38.   return $data;
  39. }
  40. add_shortcode( 'subcats', 'subcats_func' );
  41.  
  42.  function the_services_navigations(){
  43.  $category = get_queried_object()->term_id;
  44.  $cat_data = get_categories( array( 'parent' => $category, 'hide_empty' => 0 ) );
  45.   if ( $cat_data ) {
  46.     $cat_links = '';
  47.     foreach ( $cat_data as $one_cat_data)
  48.         $cat_links .= sprintf( '<a class="n-cat" href="%s">%s</a>', get_category_link( $one_cat_data->term_id ) , $one_cat_data->cat_name );
  49.     printf( '<div class="navy-cat">%s</div>', $cat_links );
  50.   }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement