admin管理员组文章数量:1333185
This is the code I have in a include file on single template file.
Is it possible to exclude 'Media' showing as a category.
So for example if I have the following categories on a post - 'Test Test1 Media' then it should show on the blog post 'Test Test1' ONLY.
<?php
$categories = get_the_category();
foreach($categories as $cat):
?>
<a href="<?php echo get_category_link($cat->term_id); ?>">
<?php echo $cat->name; ?>
</a>
<?php endforeach; ?>
This is the code I have in a include file on single template file.
Is it possible to exclude 'Media' showing as a category.
So for example if I have the following categories on a post - 'Test Test1 Media' then it should show on the blog post 'Test Test1' ONLY.
<?php
$categories = get_the_category();
foreach($categories as $cat):
?>
<a href="<?php echo get_category_link($cat->term_id); ?>">
<?php echo $cat->name; ?>
</a>
<?php endforeach; ?>
Share
Improve this question
asked Jul 9, 2020 at 3:10
Rejaur RahmanRejaur Rahman
51 silver badge3 bronze badges
1 Answer
Reset to default 1Add this simple check to your foreach
loop:
<?php
$categories = get_the_category();
foreach($categories as $cat):
if ( $cat->name == 'Media' ) continue;
?>
<a href="<?php echo get_category_link($cat->term_id); ?>">
<?php echo $cat->name; ?>
</a>
<?php endforeach; ?>
You can check the category name against the list of categories:
<?php
$categories = get_the_category();
foreach($categories as $cat):
if ( in_array( $cat->name, array( 'Media', 'Other Category 1', 'Other Category 2' ) ) ) continue;
?>
<a href="<?php echo get_category_link($cat->term_id); ?>">
<?php echo $cat->name; ?>
</a>
<?php endforeach; ?>
本文标签: On the Blogpost I have categories showingis there a way to exclude a catgegory like 39Media39
版权声明:本文标题:On the Blogpost I have categories showing, is there a way to exclude a catgegory like 'Media'? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742281201a2446121.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论