Keyword

Exclude Certain Tags from Tag Cloud

  • Joe Campbell
  • Joe Campbell's Avatar Topic Author
  • Offline
  • Platinum Member
More
7 years 9 months ago - 7 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; ?>
Last edit: 7 years 9 months ago by Joe Campbell.

Please Log in or Create an account to join the conversation.

  • Joe Campbell
  • Joe Campbell's Avatar Topic Author
  • Offline
  • Platinum Member
More
7 years 9 months ago - 7 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:
<?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: 7 years 9 months ago by Joe Campbell.

Please Log in or Create an account to join the conversation.

More
7 years 9 months ago - 7 years 9 months ago #156760 by Ramesh Elamathi
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 :
<?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: 7 years 9 months ago by Ramesh Elamathi. Reason: Formatting

Please Log in or Create an account to join the conversation.

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
7 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; ?>

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

Please Log in or Create an account to join the conversation.

  • Joe Campbell
  • Joe Campbell's Avatar Topic Author
  • Offline
  • Platinum Member
More
7 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
  • Joe Campbell's Avatar Topic Author
  • Offline
  • Platinum Member
More
7 years 9 months ago - 7 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 :)
Last edit: 7 years 9 months ago by Joe Campbell.

Please Log in or Create an account to join the conversation.


Powered by Kunena Forum