- Posts: 438
COMMUNITY FORUM
Exclude Certain Tags from Tag Cloud
- Joe Campbell
-
Topic Author
- Offline
- Platinum Member
Less
More
8 years 9 months ago - 8 years 9 months ago #156752
by Joe Campbell
Exclude Certain Tags from Tag Cloud was created by Joe Campbell
I modified the K2 Tag Cloud and would like to exclude all tags that start with an underscore "_" or a colon ":"
Here's the code for my modified tag cloud:
<?php foreach ($tags as $tag): ?>
<?php if(!empty($tag->tag)): ?>
<li><a href="<?php echo $tag->link; ?>">
<?php echo $tag->tag; ?><span class="tagcount"> (<?php echo $tag->count; ?>)</span>
</a></li>
<?php endif; ?>
<?php endforeach; ?>
Here's the code for my modified tag cloud:
<?php foreach ($tags as $tag): ?>
<?php if(!empty($tag->tag)): ?>
<li><a href="<?php echo $tag->link; ?>">
<?php echo $tag->tag; ?><span class="tagcount"> (<?php echo $tag->count; ?>)</span>
</a></li>
<?php endif; ?>
<?php endforeach; ?>
Last edit: 8 years 9 months ago by Joe Campbell.
Please Log in or Create an account to join the conversation.
- Joe Campbell
-
Topic Author
- Offline
- Platinum Member
Less
More
- Posts: 438
8 years 9 months ago - 8 years 9 months ago #156757
by Joe Campbell
Replied by Joe Campbell on topic Exclude Certain Tags from Tag Cloud
With some help from Ramesh of K2Store/J2Store, I was able to figure it out:
Thanks @Ramesh
<?php foreach ($tags as $tag): ?>
<?php if(strpos($tag->tag, ':') !== false OR strpos($tag->tag, '_') !== false ): ?><?php else: ?>
<?php if(!empty($tag->tag)): ?>
<li><a href="<?php echo $tag->link; ?>">
<?php echo $tag->tag; ?><span class="tagcount"> (<?php echo $tag->count; ?>)</span>
</a></li>
<?php endif; ?>
<?php endif; ?>
<?php endforeach; ?>
Thanks @Ramesh
Last edit: 8 years 9 months ago by Joe Campbell.
Please Log in or Create an account to join the conversation.
- Ramesh Elamathi
-
- Offline
- Senior Member
8 years 9 months ago - 8 years 9 months ago #156760
by Ramesh Elamathi
Lead developer at www.j2store.org
Replied by Ramesh Elamathi on topic Exclude Certain Tags from Tag Cloud
@joe Great that you worked out based on my hint.
The better version is :
The better version is :
<?php foreach ($tags as $tag): ?>
<?php if( (strpos($tag->tag, ':') === false AND strpos($tag->tag, '_') === false) && !empty($tag->tag) ): ?>
<li>
<a href="<?php echo $tag->link; ?>">
<?php echo $tag->tag; ?>
<span class="tagcount"> (<?php echo $tag->count; ?>)</span>
</a>
</li>
<?php endif; ?>
<?php endforeach; ?>
Lead developer at www.j2store.org
Last edit: 8 years 9 months ago by Ramesh Elamathi. Reason: Formatting
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
Less
More
- Posts: 15920
8 years 9 months ago #156761
by Krikor Boghossian
Replied by Krikor Boghossian on topic Exclude Certain Tags from Tag Cloud
As Joe stated the code should be:
Please update the following post with the revised code, the forum will not allow me to (saying my edit is spam):
<?php foreach ($tags as $tag): ?>
<?php if( (strpos($tag->tag, ':') === false AND strpos($tag->tag, '_') === false) && !empty($tag->tag) ): ?>
<li><a href="<?php echo $tag->link; ?>">
<?php echo $tag->tag; ?><span class="tagcount"> (<?php echo $tag->count; ?>)</span>
</a></li>
<?php endif; ?>
<?php endforeach; ?>
Please Log in or Create an account to join the conversation.
- Joe Campbell
-
Topic Author
- Offline
- Platinum Member
Less
More
- Posts: 438
8 years 9 months ago #156762
by Joe Campbell
Replied by Joe Campbell on topic Exclude Certain Tags from Tag Cloud
Thanks @Krikor, @Ramesh' posted the correct code that I am using - many thanks
Please Log in or Create an account to join the conversation.
- Joe Campbell
-
Topic Author
- Offline
- Platinum Member
Less
More
- Posts: 438
8 years 9 months ago - 8 years 9 months ago #156763
by Joe Campbell
Replied by Joe Campbell on topic Exclude Certain Tags from Tag Cloud
I hope others find this code useful.
For me, I use tags for both frontend and backend purposes.
All backend tags either start with _ or : so to ensure all backend tags never show up in the frontend this code is necessary :)
For me, I use tags for both frontend and backend purposes.
All backend tags either start with _ or : so to ensure all backend tags never show up in the frontend this code is necessary :)
Last edit: 8 years 9 months ago by Joe Campbell.
Please Log in or Create an account to join the conversation.