Php 删除此foreach循环中的数组元素
我在Wordpress中使用了这个代码来列出标签和它们被使用的次数。这是密码Php 删除此foreach循环中的数组元素,php,arrays,wordpress,foreach,Php,Arrays,Wordpress,Foreach,我在Wordpress中使用了这个代码来列出标签和它们被使用的次数。这是密码 <?php $tags = get_tags( array('orderby' => 'count', 'order' => 'DESC') ); foreach ( (array) $tags as $tag ) { ?> <li class="list-group-item"> <span class="badge"><?php echo $tag->co
<?php
$tags = get_tags( array('orderby' => 'count', 'order' => 'DESC') );
foreach ( (array) $tags as $tag ) { ?>
<li class="list-group-item">
<span class="badge"><?php echo $tag->count; ?></span>
<?php echo $tag->name; ?>
</li>
<?php }
?>
结果如下:
所以我想从列表中删除标记“动物”。我一直在寻找其他问题,但我无法解决我的问题。谢谢你的回答 您可以按以下方式更新代码:
<?php
$tags = get_tags( array('orderby' => 'count', 'order' => 'DESC') );
foreach ( (array) $tags as $tag ) {
if ($tag->name == "Animals" ) { continue; }
?>
<li class="list-group-item">
<span class="badge"><?php echo $tag->count; ?></span>
<?php echo $tag->name; ?>
</li>
<?php }
?>
您可以按以下方式更新代码:
<?php
$tags = get_tags( array('orderby' => 'count', 'order' => 'DESC') );
foreach ( (array) $tags as $tag ) {
if ($tag->name == "Animals" ) { continue; }
?>
<li class="list-group-item">
<span class="badge"><?php echo $tag->count; ?></span>
<?php echo $tag->name; ?>
</li>
<?php }
?>
您可以按以下方式更新代码:
<?php
$tags = get_tags( array('orderby' => 'count', 'order' => 'DESC') );
foreach ( (array) $tags as $tag ) {
if ($tag->name == "Animals" ) { continue; }
?>
<li class="list-group-item">
<span class="badge"><?php echo $tag->count; ?></span>
<?php echo $tag->name; ?>
</li>
<?php }
?>
您可以按以下方式更新代码:
<?php
$tags = get_tags( array('orderby' => 'count', 'order' => 'DESC') );
foreach ( (array) $tags as $tag ) {
if ($tag->name == "Animals" ) { continue; }
?>
<li class="list-group-item">
<span class="badge"><?php echo $tag->count; ?></span>
<?php echo $tag->name; ?>
</li>
<?php }
?>
使用排除参数作为获取标签()。在我的示例中,我将术语ID设置为5;请确保将其替换为正确的值
exclude
也可以是一个数组,允许您排除多个标记
更改:
$tags = get_tags( array( 'orderby' => 'count', 'order' => 'DESC' ) );
致:
使用get_tags()
的exclude
参数。在我的示例中,我将术语ID设置为5;请确保将其替换为正确的值
exclude
也可以是一个数组,允许您排除多个标记
更改:
$tags = get_tags( array( 'orderby' => 'count', 'order' => 'DESC' ) );
致:
使用get_tags()
的exclude
参数。在我的示例中,我将术语ID设置为5;请确保将其替换为正确的值
exclude
也可以是一个数组,允许您排除多个标记
更改:
$tags = get_tags( array( 'orderby' => 'count', 'order' => 'DESC' ) );
致:
使用get_tags()
的exclude
参数。在我的示例中,我将术语ID设置为5;请确保将其替换为正确的值
exclude
也可以是一个数组,允许您排除多个标记
更改:
$tags = get_tags( array( 'orderby' => 'count', 'order' => 'DESC' ) );
致:
使用下列内容
<?php
$tags = get_tags( array('orderby' => 'count', 'order' => 'DESC') );
foreach ( (array) $tags as $tag ) {
if ($tag->name != "Animals" ) {
?>
<li class="list-group-item">
<span class="badge"><?php echo $tag->count; ?></span>
<?php echo $tag->name; ?>
</li>
<?php
}
}
?>
使用以下命令
<?php
$tags = get_tags( array('orderby' => 'count', 'order' => 'DESC') );
foreach ( (array) $tags as $tag ) {
if ($tag->name != "Animals" ) {
?>
<li class="list-group-item">
<span class="badge"><?php echo $tag->count; ?></span>
<?php echo $tag->name; ?>
</li>
<?php
}
}
?>
使用以下命令
<?php
$tags = get_tags( array('orderby' => 'count', 'order' => 'DESC') );
foreach ( (array) $tags as $tag ) {
if ($tag->name != "Animals" ) {
?>
<li class="list-group-item">
<span class="badge"><?php echo $tag->count; ?></span>
<?php echo $tag->name; ?>
</li>
<?php
}
}
?>
使用以下命令
<?php
$tags = get_tags( array('orderby' => 'count', 'order' => 'DESC') );
foreach ( (array) $tags as $tag ) {
if ($tag->name != "Animals" ) {
?>
<li class="list-group-item">
<span class="badge"><?php echo $tag->count; ?></span>
<?php echo $tag->name; ?>
</li>
<?php
}
}
?>
给定WordPress,这是最好的解决方案。给定WordPress,这是最好的解决方案。给定WordPress,这是最好的解决方案。给定WordPress,这是最好的解决方案。很好!另一方面,如何仅显示所需的标记?例如,我有很多标记,但我只想显示'Tech'和'News'@CristianTirado如果你只想显示一组特定的标记,你应该使用include参数。看,只需使用include而不是exclude。这很好!另一方面,如何仅显示所需的标记?例如,我有很多标记,但我只想显示'Tech'和'News'@CristianTirado如果你只想显示一组特定的标记,你应该使用include参数。看,只需使用include而不是exclude。这很好!另一方面,如何仅显示所需的标记?例如,我有很多标记,但我只想显示'Tech'和'News'@CristianTirado如果你只想显示一组特定的标记,你应该使用include参数。看,只需使用include而不是exclude。这很好!另一方面,如何仅显示所需的标记?例如,我有很多标记,但我只想显示'Tech'和'News'@CristianTirado如果你只想显示一组特定的标记,你应该使用include参数。请看,只需使用include而不是exclude。