- Posts: 6
COMMUNITY FORUM
[SOLVED] module which displays a total count of items
- Machroel
-
Topic Author
- Offline
- New Member
I am new in using K2 and after a long search I am wondering: Is there a module which displays a total count of all items or categories? Maybe I didn't look right, but I just can't seem to find it.
Is there anyone who could help me finding an answer? Thanks in advance!
Please Log in or Create an account to join the conversation.
- Lefteris
-
- Offline
- Platinum Member
- Posts: 8743
Please Log in or Create an account to join the conversation.
- Machroel
-
Topic Author
- Offline
- New Member
- Posts: 6
I just want my visitors to show (in a module) how many items/articles I have in total.
My items are guitar tabs for musicians and therefor it is nice to see how many tabs and artists or bands are published on my website.
So there is a K2 module in administrator which will do this? Can you tell me which one?
Please Log in or Create an account to join the conversation.
- Lefteris
-
- Offline
- Platinum Member
- Posts: 8743
<?php
$db = JFactory::getDbo();
$db->setQuery("SELECT COUNT(*) FROM #__k2_items WHERE published = 1 AND trash = 0");
$result = $db->loadResult();
?>
<span>Total : <?php echo $result; ?></span>
Note that this code does not take into consideration the access level of the items and the start publishing and finish publishing dates.
Please Log in or Create an account to join the conversation.
- Machroel
-
Topic Author
- Offline
- New Member
- Posts: 6
Please Log in or Create an account to join the conversation.
- Machroel
-
Topic Author
- Offline
- New Member
- Posts: 6
<?php
$db = JFactory::getDbo();
$db->setQuery("SELECT COUNT(*) FROM #__k2_items WHERE published = 1 AND trash = 0");
$result = $db->loadResult();
?>
I placed your last line: <span>Total : <?php echo $result; ?></span> in a HTML Module
Sorry for my ignorance...
Please Log in or Create an account to join the conversation.
- Lefteris
-
- Offline
- Platinum Member
- Posts: 8743
Please Log in or Create an account to join the conversation.
- Machroel
-
Topic Author
- Offline
- New Member
- Posts: 6
Thanks again for your expertise!
Please Log in or Create an account to join the conversation.
- Lefteris
-
- Offline
- Platinum Member
- Posts: 8743
Please Log in or Create an account to join the conversation.
- Machroel
-
Topic Author
- Offline
- New Member
- Posts: 6
I misused the module as you said. I choose archive where I needed to choose ' custom' .
' Problem' solved :)
Please Log in or Create an account to join the conversation.
- Lefteris
-
- Offline
- Platinum Member
- Posts: 8743
Please Log in or Create an account to join the conversation.
- Chris Casconi
-
- Offline
- New Member
- Posts: 16
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
- Posts: 15920
eg:
AND catid = 5
Please Log in or Create an account to join the conversation.
- Chris Casconi
-
- Offline
- New Member
- Posts: 16
<?php
$db = JFactory::getDbo();
$db->setQuery("SELECT COUNT(*) FROM #__k2_categories WHERE published = 1 AND trash = 0");
$result = $db->loadResult();
?>
Where in the above code?
Please Log in or Create an account to join the conversation.
- Chris Casconi
-
- Offline
- New Member
- Posts: 16
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
- Posts: 15920
Please Log in or Create an account to join the conversation.
- Dennis Miliopoulos
-
- Offline
- Junior Member
- Posts: 21
This post was really helpfull but i need something extra for my case.
I want to display the total count of items of specific subcategories.
I now have the following category structure:
Parent Category A (0 Items)
- Child Category A (4 items)
- Child Category B (1 item)
- Child Category C (2 items)
Parent Category B (20 items)
Parent Category C (10 items)
So the goal is to display that the "Parent Category A" has 7 items
Please Log in or Create an account to join the conversation.
- Dennis Miliopoulos
-
- Offline
- Junior Member
- Posts: 21
<?php
$db = JFactory::getDbo();
$db->setQuery("SELECT COUNT(*) FROM #__k2_items i, #__k2_categories c WHERE i.catid = c.id AND i.published = 1 AND i.trash = 0 AND c.parent = xx");
$result = $db->loadResult();
?>
xx -> parent category id
Please Log in or Create an account to join the conversation.
- IgorKysin
-
- Offline
- New Member
- Posts: 15
This code counting piblished and dont trashed items. But if item published in future, code counting too. How exclude from counting pending items?
Thanks!
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
- Posts: 15920
Did you insert WHERE published = 1 in the query as well?
Please Log in or Create an account to join the conversation.