2013-09-19 2 views
0

Я создал код для отображения срока моей таксономии. Но для одной из моих таксономии у меня есть суб-термин или подкатегория. И я не понимаю, как я могу отображать сообщения подкатегории моей таксономии.Показать сообщения подкатегории моей таксономии

Мой код в functions.php

function theme_lasts_posts_shortcode($atts, $content = null) {  
    extract(shortcode_atts(array(
     "posttype" => '', 
     "taxonomy" => '', 
     "term" => '', 
     "class" => '', 
     "exclude" => '', 
    ), $atts)); 

    $output = '<div class="derniersarticles">'; 

    if ($posttype != '') { 
     $loop = new WP_Query(array('post_type' => $posttype, 'taxonomy' => $taxonomy,'term' => $term, 'posts_per_page' => 100, 'post__not_in' => array($exclude))); 
    } else { 
     $loop = new WP_Query(array('post_type' => $posttype, 'posts_per_page' => 100)); 
    } 

    while ($loop->have_posts()) : $loop->the_post(); 

      $output .= '<div class="'. $class .'">'; 
      $output .= '<div class="thumb">'; 
      $output .= '<a href="' . get_permalink() . '">' . get_the_post_thumbnail() . '</a>'; 
      $output .= '</div>'; 
      $output .= '<h3><a href="' . get_permalink() . '">' . get_the_title() . '</a></h3>'; 
      $output .= '</div>'; 

    endwhile; 

    $output .= '</div>'; 
    return $output; 
} 

add_shortcode('DerniersArticles', 'theme_lasts_posts_shortcode'); 

ответ

0

Если я понял вопрос corectly вам нужно получить сообщения от детей родительской категории из пользовательской таксономии?

В этом случае, попробуйте следующее:

 <?php 
     $father = get_term_by('name', 'main_category_name', 'product_cat'); 
     $father_id = $father->term_id; 
     $taxonomy_name = 'product_cat'; 
     $children = get_term_children($father_id, $taxonomy_name); 
     echo '<div class="sidebar_cat">'; 
     echo '<h5 class="sidebar_heading">'.'main_category_name'.'</h5>'; 
     echo '<ul class="sidebar_text">'; 
     foreach ($children as $child) { 
    $term = get_term_by('id', $child, $taxonomy_name); 
    echo '<li><a href="' . get_term_link($term->name, $taxonomy_name) .   '">'.$term->name . '</a></li>'; 

      } 
      echo '</ul>'; ?> 
Смежные вопросы