Keyword

[SOLVED] module which displays a total count of items

  • Machroel
  • Machroel's Avatar Topic Author
  • Offline
  • New Member
More
10 years 2 weeks 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
10 years 2 weeks ago #125975 by Lefteris
Hi. There is such a module in administration. What do you want to achieve exactly?

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

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

  • Machroel
  • Machroel's Avatar Topic Author
  • Offline
  • New Member
More
10 years 2 weeks 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
10 years 2 weeks 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.

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

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

  • Machroel
  • Machroel's Avatar Topic Author
  • Offline
  • New Member
More
10 years 2 weeks 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
10 years 2 weeks 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
10 years 2 weeks 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.

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

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

  • Machroel
  • Machroel's Avatar Topic Author
  • Offline
  • New Member
More
10 years 1 week 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
10 years 1 week 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.

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

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

  • Machroel
  • Machroel's Avatar Topic Author
  • Offline
  • New Member
More
10 years 5 days 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.


Powered by Kunena Forum