2015-05-21 2 views
0

У меня есть этот код, который прекрасно работает, чтобы показать подкатегорию имя и ссылку на конкретной родительской категории моего выбора:Wordpress: Дисплей Подкатегория Имя Без Link

<?php 
$taxonomy = 'category'; 

// get the term IDs assigned to post. 
$post_terms = wp_get_object_terms($post->ID, $taxonomy, array('fields' => 'ids')); 
// separator between links 
$categories = get_the_category(); 
$parentid = '6'; 

if (!empty($post_terms) && !is_wp_error($post_terms)) { 

$term_ids = implode(',' , $post_terms); 
$terms = strtr(wp_list_categories('title_li=&style=none&echo=0&child_of=' . $parentid . '&taxonomy=' . $taxonomy . '&include=' . $term_ids), array('<br />' => ' <br /> ')); 
echo preg_replace('@\s<br />\s\[email protected]', '', $terms); 
} 
?>        

Теперь я хочу, чтобы иметь возможность делать то же самое но БЕЗ кода выше, генерируя ссылку автоматически. Есть идеи?

ответ

0

Использование get_categories() вместо wp_list_categories()

$terms = get_categories("child_of={$parentid}&include={$term_ids}"); 

foreach($terms as $term) 
    echo $term->name; 
+0

Это работало. Благодаря! – Armin

Смежные вопросы