Max*_*ynn 0 php tags wordpress
研究在 Wordpress 中的 Archieve.php 文件上显示标签,以仅显示当前类别下的标签。
目前我所能做的就是显示所有标签,而不是使用以下代码仅选择当前类别下的标签:
<ul id="blog-tags">
<?php
$tags = get_tags();
if ( $tags ) {
foreach ( $tags as $tag ) {
echo '<li>';
if ( (int) $tag->term_id === get_queried_object_id() )
echo "<b>$tag->name</b>";
else
printf(
'<a href="%1$s">%2$s</a>',
get_tag_link( $tag->term_id ),
$tag->name
);
echo '</li>';
}
}
?>
</ul>
Run Code Online (Sandbox Code Playgroud)
是否可以操纵上面的代码来执行我想要的操作?或者我必须采取完全不同的方法。
不太确定这就是您想要的,但基本上只需要按类别循环所有帖子,然后获取这些帖子的标签。
您可以尝试类似的方法来获取当前类别的所有标签。您需要对它进行一些操作才能将其以您想要的方式格式化HTML
。
<?php
$custom_query = new WP_Query(
array(
'cat' => get_query_var('cat')
)
);
if ($custom_query->have_posts()) :
while ($custom_query->have_posts()) : $custom_query->the_post();
$posttags = get_the_tags();
if ($posttags) {
foreach($posttags as $tag) {
$all_tags[] = $tag->term_id;
}
}
endwhile;
endif;
$tags_arr = array_unique($all_tags);
$tags_str = implode(",", $tags_arr);
$args = array(
'smallest' => 12,
'largest' => 12,
'unit' => 'px',
'number' => 0,
'format' => 'list',
'include' => $tags_str
);
wp_tag_cloud($args);
// or use <?php $my_tags = wp_tag_cloud( 'format=array' ); ?> to have them in an array that you can format after
?>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2678 次 |
最近记录: |