- Posts: 438
COMMUNITY FORUM
Category & Tag Count Code Snippet
- Joe Campbell
-
Topic Author
- Offline
- Platinum Member
Less
More
9 years 3 months ago #150292
by Joe Campbell
Category & Tag Count Code Snippet was created by Joe Campbell
How can I display the count of a single category and tag?
for example...
<?php echo $category[ID:34]->count[value] ?>
<?php echo $tag[ID:65]->count[value] ?>
for example...
<?php echo $category[ID:34]->count[value] ?>
<?php echo $tag[ID:65]->count[value] ?>
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
Less
More
- Posts: 15920
9 years 3 months ago #150297
by Krikor Boghossian
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Replied by Krikor Boghossian on topic Category & Tag Count Code Snippet
Hello Joe,
This will help as a starting point:
www.joomlaworks.net/forum/k2-en/41833-solved-retrieve-count-of-items-of-user#144866
To load the tag's count you need a different query.
Do not not forget to assign the tag's ID to the $tag_id variable.
The variable names are just for demo purposes.
This will help as a starting point:
www.joomlaworks.net/forum/k2-en/41833-solved-retrieve-count-of-items-of-user#144866
<?php
$cat_id = CATEGORY_ID;
$db = JFactory::getDBO(); ?>
<?php $select = "SELECT COUNT(*) FROM #__k2_items WHERE catid=$cat_id"; ?>
<?php $db->setQuery($select); ?>
<?php $resultitems = $db->loadresult(); ?>
<?php echo $resultitems; ?>
To load the tag's count you need a different query.
<?php $select = "SELECT COUNT(*) FROM #__k2_tags_xref WHERE tagID = $tag_id"; ?>
Do not not forget to assign the tag's ID to the $tag_id variable.
The variable names are just for demo purposes.
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
-
Topic Author
- Offline
- Platinum Member
Less
More
- Posts: 438
9 years 3 months ago #150301
by Joe Campbell
Replied by Joe Campbell on topic Category & Tag Count Code Snippet
Thanks for the speedy response @Krikor
Two things:
1. I am not a coder, so I require very explicit instructions (ENTER-CAT-ID-HERE text preferably :)
2. I need to render a count for multiple categories in an item (entered via content editor or module), thus a set-up snippet and then along with simple snippets to render each category count is needed. How would I do this?
Thank You
Two things:
1. I am not a coder, so I require very explicit instructions (ENTER-CAT-ID-HERE text preferably :)
2. I need to render a count for multiple categories in an item (entered via content editor or module), thus a set-up snippet and then along with simple snippets to render each category count is needed. How would I do this?
Thank You
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
Less
More
- Posts: 15920
9 years 3 months ago #150306
by Krikor Boghossian
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Replied by Krikor Boghossian on topic Category & Tag Count Code Snippet
1) $cat_id = CATEGORY_ID; :)
Simply replace the CATEGORY_ID with the actual ID.
2) I am not sure what you are trying to achieve, do you need a snippet to print the code based on the given category?
Simply replace the CATEGORY_ID with the actual ID.
2) I am not sure what you are trying to achieve, do you need a snippet to print the code based on the given category?
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
-
Topic Author
- Offline
- Platinum Member
Less
More
- Posts: 438
9 years 3 months ago #150314
by Joe Campbell
Replied by Joe Campbell on topic Category & Tag Count Code Snippet
I would like to display "various" categories along with their count:
Category A (23 items)
Category B (2 items)
Category F (5 items)
Category N (11 items)
Category P (7 items)
Category Z (32 items)
This is why I posted a suggestion on Git to offer a category selection option to the Category List Menu :)
I almost ready to show you my site. Let's wait until then so you can see exact execution.
Thanks KB
Category A (23 items)
Category B (2 items)
Category F (5 items)
Category N (11 items)
Category P (7 items)
Category Z (32 items)
This is why I posted a suggestion on Git to offer a category selection option to the Category List Menu :)
I almost ready to show you my site. Let's wait until then so you can see exact execution.
Thanks KB
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
Less
More
- Posts: 15920
9 years 3 months ago #150318
by Krikor Boghossian
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Replied by Krikor Boghossian on topic Category & Tag Count Code Snippet
Hmm, wouldn't the K2 Tools module help you?
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
-
Topic Author
- Offline
- Platinum Member
Less
More
- Posts: 438
9 years 3 months ago #150324
by Joe Campbell
Replied by Joe Campbell on topic Category & Tag Count Code Snippet
Not when you trying to display specific categories (vs. all categories within a parent category) or various categories that are not within the same parent category.
This is my suggestion:
github.com/joomlaworks/k2-v3-dev-build/issues/275
So the only current option is to render each category count independently.
The links will be hard coded because they will not change, but the counts need to be dynamic.
This is my suggestion:
github.com/joomlaworks/k2-v3-dev-build/issues/275
So the only current option is to render each category count independently.
The links will be hard coded because they will not change, but the counts need to be dynamic.
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
Less
More
- Posts: 15920
9 years 3 months ago #150331
by Krikor Boghossian
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Replied by Krikor Boghossian on topic Category & Tag Count Code Snippet
Basically you need a merge/ mashup of mod_menu and mod_k2_tools.
I think a custom mod_menu override (with caching) would do the trick.
I think a custom mod_menu override (with caching) would do the trick.
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.