我做了這個劇本,如何在foreach WordPress模板中獲取tag_description?
<?php
function top_tags() {
$tags = get_tags();
if (empty($tags))
return;
$counts = $tag_links = array();
foreach ((array) $tags as $tag) {
$counts[$tag->name] = $tag->count;
$tag_links[$tag->name] = get_tag_link($tag->term_id);
}
asort($counts);
$counts = array_reverse($counts, true);
$i = 0;
foreach ($counts as $tag => $count) {
$i++;
$tag_link = clean_url($tag_links[$tag]);
$tag = str_replace(' ', ' ', wp_specialchars($tag));
if($i < 11){
print "<li><a href=\"$tag_link\">$tag ($count) </a></li>";
}
}
}
?>
但我似乎無法得到每個標籤的tag_description。如果我在foreach函數中使用$description = tag_description();
,它不會顯示任何內容。
不,仍然沒有看到。儘管感謝您的回答。 – Siyah 2014-10-16 11:32:32
您上次編輯的作品。謝謝你,謝謝! – Siyah 2014-10-16 11:33:21
你有沒有試過我的編輯?標籤更改爲「post_tag」中的get_term_by – 2014-10-16 11:33:37