Keyword

K2 tag counter (muliticategory substitution)

  • Sławomir Kamiński
  • Sławomir Kamiński's Avatar Topic Author
  • Offline
  • New Member
More
10 years 1 month ago #130960 by Sławomir Kamiński
K2 tag counter (muliticategory substitution) was created by Sławomir Kamiński
Hello!

I wanted to do something, that will substitute a multicategory handling for K2 on my page. I decided to use tags for that. Instead of K2/Categories I plan to make a special menu which contains K2/Tag type items. This way I could assign an image for each "category" also.

But one thing is missing. I don't know how to obtain an tag usage counter. I mean a number which is equal to a number of articles with particular tag defined, to substitute the number of items in category. Whole menu should looks like that:

<image1> Pseudocategory1 (23) <image2> Pseudocategory2 (34)
<image3> Pseudocategory3 (12) <image4> Pseudocategory4 (59)
<image5> Pseudocategory5 (73) <image6> Pseudocategory6 (1)

I hope I explained it clear enough.:) Could anyone help me, please?

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

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
10 years 1 month ago #130961 by Krikor Boghossian
Replied by Krikor Boghossian on topic Re: K2 tag counter (muliticategory substitution)
You need to perform custom queries for this:

This retrieves the count of items for each tag
<?php 
$db = JFactory::getDbo(); 
$db->setQuery("SELECT COUNT(*) FROM #_k2_tags_xref WHERE tagID = YOUR_TAG_ID"); 
$result = $db->loadResult(); 
?> 

To retrieve the count for specific categories please see this post:
getk2.org/community/English-K2-Community/191343-SOLVED-module-which-displays-a-total-count-of-items#196779

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

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

  • Sławomir Kamiński
  • Sławomir Kamiński's Avatar Topic Author
  • Offline
  • New Member
More
10 years 1 month ago #130962 by Sławomir Kamiński
Replied by Sławomir Kamiński on topic Re: K2 tag counter (muliticategory substitution)
Thanks for your help!

It works, but I have to put "#__k2_tags_xref" instead of "#_k2_tags_xref" (probably you made a typo). Could you tell me, which file should I edit (or make template override, if possible), to make this information automatically displayed with each tag name in my menu?

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

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
10 years 1 month ago #130963 by Krikor Boghossian
Replied by Krikor Boghossian on topic Re: K2 tag counter (muliticategory substitution)
If you want this info in your mod_menu then I think you should make a new mod_menu template.

Another way would be to populate these values with JavaScript, eg: display them somewhere in your index.php and with a JS attach them to your menu items.

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

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

  • Sławomir Kamiński
  • Sławomir Kamiński's Avatar Topic Author
  • Offline
  • New Member
More
10 years 1 month ago #130964 by Sławomir Kamiński
Replied by Sławomir Kamiński on topic Re: K2 tag counter (muliticategory substitution)
Finally I decided to use Tags cloud from K2 tools module. I edited file \modules\mod_k2_tools\tmpl\tags.php so now it looks this way:
<?php
/**
 * @version		2.6.x
 * @package		K2
 * @author		JoomlaWorks https://www.joomlaworks.net
 * @copyright	Copyright (c) 2006 - 2014 JoomlaWorks Ltd. All rights reserved.
 * @license		GNU/GPL license: http://www.gnu.org/copyleft/gpl.html
 */

// no direct access
defined('_JEXEC') or die;

?>

<?php $colNumber = 0; ?>

<div id="k2ModuleBox<?php echo $module->id; ?>" class="k2TagCloudBlock<?php if($params->get('moduleclass_sfx')) echo ' '.$params->get('moduleclass_sfx'); ?>">
	<?php foreach ($tags as $tag): ?>
		<?php if(!empty($tag->tag)): ?>
			<?php
				$path = "images/pix/categories/";													// path do 'category' image directory
				$default_img = $path . "default.png";												// name of picture to display for categories without image dedicated
	
				$polishChars = array('ą', 'ć', 'ę', 'ł', 'ń', 'ó', 'ś', 'ż', 'ź');
				$replace     = array('a', 'c', 'e', 'l', 'n', 'o', 's', 'z', 'z');
				$img = mb_strtolower($tag->tag, 'UTF-8');
				$img = str_replace($polishChars, $replace, $img);								// get rid of polish accents
				$img = $path . strtolower(str_replace(" ", "_", $img)) . ".png";			// exchange spaces to '_' & make lowercase
				if (!file_exists($img))
					$img = $default_img;
			?>
			
			<?php if ($colNumber % 3 == 0) echo "<div class=\"singleTagRow\">"; ?>
				<div class="singleTag">
					<a href="<?php echo $tag->link; ?>" style="font-size:<?php echo $tag->size; ?>%" title="<?php echo $tag->count.' '.JText::_('K2_ITEMS_TAGGED_WITH').' '.K2HelperUtilities::cleanHtml($tag->tag); ?>">
						<div class="singleTagImg"> <img src="<?php echo $img; ?>"> </div>
						<div class="singleTagTxt"> <?php echo $tag->tag; ?> (<?php echo $tag->count; ?>) </div>
					</a>
				</div>
			<?php if ($colNumber++ % 3 == 2) echo "</div>"; ?>
		<?php endif; ?>
	<?php endforeach; ?>
	<?php if (($colNumber-1) % 3 !=2) echo "</div>"; ?>
	<div class="clr"></div>
</div>
	<hr id="companiesListHR">

Playing a bit with template.css file I got result like on screenshot in attachment. If exists an image with the same name as tag name, it's loaded automaticaly. If not, default image is used.

Attachment not found

Attachments:

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

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
10 years 1 month ago #130965 by Krikor Boghossian
Replied by Krikor Boghossian on topic Re: K2 tag counter (muliticategory substitution)
Niice :)

Also thanks for sharing this with the community Sławomir.

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

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


Powered by Kunena Forum