Php 可湿性粉剂:数帖子共享相同的标签?
欢呼 我是新的可湿性粉剂法典。下面是我为检索特定帖子的标签而编写的代码示例:Php 可湿性粉剂:数帖子共享相同的标签?,php,wordpress,Php,Wordpress,欢呼 我是新的可湿性粉剂法典。下面是我为检索特定帖子的标签而编写的代码示例: <?php global $post; $post_tags = get_the_tags($post->ID); if ($post_tags) { foreach($post_tags as $tag){ echo '<div class="tag"><a href="' .
<?php
global $post;
$post_tags = get_the_tags($post->ID);
if ($post_tags) {
foreach($post_tags as $tag){
echo '<div class="tag"><a href="' . get_site_url() . '/tag/' . $tag->name . '">' . $tag->name . '</a></div>';
}
}
?>
我知道这应该很简单,但却找不到方法。
PS:$post_tags_count——这只是一个例子,说明我必须统计共享同一标签的帖子
我相信我可以添加一个$count=0的循环$计数++;但也许WP提供了更好的解决方案?谢谢大家 好的。我自己也弄明白了。希望它对某人有用:
<?php
global $post;
$post_tags = get_the_tags($post->ID);
if ($post_tags) {
foreach($post_tags as $tag){
$tag_count = $tag->count;
if($tag_count > 1){
echo '<div class="tag"><a href="' . get_site_url() . '/tag/' . $tag->name . '">' . $tag->name . '</a></div>';
}
}
}
?>
好的。我自己也弄明白了。希望它对某人有用:
<?php
global $post;
$post_tags = get_the_tags($post->ID);
if ($post_tags) {
foreach($post_tags as $tag){
$tag_count = $tag->count;
if($tag_count > 1){
echo '<div class="tag"><a href="' . get_site_url() . '/tag/' . $tag->name . '">' . $tag->name . '</a></div>';
}
}
}
?>