Keyword

[SOLVED] module which displays a total count of items

  • Machroel
  • Machroel's Avatar Topic Author
  • Offline
  • New Member
More
11 years 2 months ago #125974 by Machroel
Hi K2 users,

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.

More
11 years 2 months ago #125975 by Lefteris
Hi. There is such a module in administration. What do you want to achieve exactly?

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

  • Machroel
  • Machroel's Avatar Topic Author
  • Offline
  • New Member
More
11 years 2 months ago #125976 by Machroel
thanks for answering...

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.

More
11 years 2 months ago #125977 by Lefteris
This module is used in administration only and can't be used for guests. You can however try:
<?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
  • Machroel's Avatar Topic Author
  • Offline
  • New Member
More
11 years 2 months ago #125978 by Machroel
Thanks very much for your reply! I wil try your solution and let you know the results!

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

  • Machroel
  • Machroel's Avatar Topic Author
  • Offline
  • New Member
More
11 years 2 months ago #125979 by Machroel
..maybe a stupid question to ask...but where-in which file- should I put these lines?

<?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.

More
11 years 1 month ago #125980 by Lefteris
This depends where you want to put this. Joomla! custom HTML module does not allow PHP execution so you might want to use the K2 Tools custom code module.

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

  • Machroel
  • Machroel's Avatar Topic Author
  • Offline
  • New Member
More
11 years 1 month ago #125981 by Machroel
Thank you.. :) The K2 custom field -module tools- does the work indeed! It is still though not presize what I want [it now shows Month-Year (total)...and I just want total: (99)] ...but it gives me enough direction to work with.
Thanks again for your expertise!

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

More
11 years 1 month ago #125982 by Lefteris
Probably you have misused the module. I suggested to set K2 tools usage to custom code and then use the code i provided. Probably are using the K2 tools module as archive.

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

  • Machroel
  • Machroel's Avatar Topic Author
  • Offline
  • New Member
More
11 years 1 month ago #125983 by Machroel
That's it!!! Thank you, thank you!
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.

More
11 years 1 month ago #125984 by Lefteris
You are welcome.

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

More
10 years 9 months ago #125985 by Chris Casconi
Replied by Chris Casconi on topic Re: module which displays a total count of items
I know this topic is solved, but is there a way to drill this down even further and make the article count for a specific category inside K2?

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

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
10 years 9 months ago #125986 by Krikor Boghossian
Replied by Krikor Boghossian on topic Re: module which displays a total count of items
Sure you need to add the catid check in your query.
eg:
AND catid = 5
Where 5 is your category's id.

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

More
10 years 9 months ago #125987 by Chris Casconi
Replied by Chris Casconi on topic Re: module which displays a total count of items
Where in the code do I insert that?

<?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.

More
10 years 9 months ago #125988 by Chris Casconi
Replied by Chris Casconi on topic Re: module which displays a total count of items
I think I've got it worked out!

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

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
10 years 9 months ago #125989 by Krikor Boghossian
Replied by Krikor Boghossian on topic Re: module which displays a total count of items
Nice to hear that.

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

  • Dennis Miliopoulos
  • Dennis Miliopoulos's Avatar
  • Offline
  • Junior Member
More
10 years 6 months ago #125990 by Dennis Miliopoulos
Replied by Dennis Miliopoulos on topic Re: module which displays a total count of items
Hello,

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
  • Dennis Miliopoulos's Avatar
  • Offline
  • Junior Member
More
10 years 6 months ago #125991 by Dennis Miliopoulos
Replied by Dennis Miliopoulos on topic Re: module which displays a total count of items
I found the solution to my previous post.

<?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.

More
10 years 3 months ago #136654 by IgorKysin
Replied by IgorKysin on topic Re: module which displays a total count of items
Hello, again!
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
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
10 years 3 months ago #136657 by Krikor Boghossian
Replied by Krikor Boghossian on topic Re: module which displays a total count of items
Hello,

Did you insert WHERE published = 1 in the query as well?

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


Powered by Kunena Forum