Number total of articles per author

For Joomla! 4.x Coding related discussions, you could also use: http://groups.google.com/group/joomla-dev-general

Moderator: ooffick

Forum rules
Post Reply
Von Barron
Joomla! Apprentice
Joomla! Apprentice
Posts: 6
Joined: Fri Apr 08, 2016 9:19 am

Number total of articles per author

Post by Von Barron » Fri Sep 15, 2023 8:10 pm

Hi all,
In the list of the authors of my site, I want to display the number total of articles for every author.
What would be the code for this, please?
Thx in advance

User avatar
Per Yngve Berg
Joomla! Master
Joomla! Master
Posts: 30311
Joined: Mon Oct 27, 2008 9:27 pm
Location: Romerike, Norway

Re: Number total of articles per author

Post by Per Yngve Berg » Fri Sep 15, 2023 8:49 pm

Code: Select all

select count() from #_content where author=<uid>

Von Barron
Joomla! Apprentice
Joomla! Apprentice
Posts: 6
Joined: Fri Apr 08, 2016 9:19 am

Re: Number total of articles per author

Post by Von Barron » Fri Sep 15, 2023 8:59 pm

Thank you!
I'm supposed to copy/paste your code where I want to display the result, right?

User avatar
ceford
Joomla! Hero
Joomla! Hero
Posts: 2021
Joined: Mon Feb 24, 2014 10:38 pm
Location: Edinburgh, Scotland
Contact:

Re: Number total of articles per author

Post by ceford » Fri Sep 15, 2023 9:20 pm

Do you have a component to display a list of Authors? If so you would use a subquery to count the number of articles for each author.

nacc
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 131
Joined: Mon Jul 03, 2023 7:08 pm

Re: Number total of articles per author

Post by nacc » Fri Sep 15, 2023 9:57 pm

Why not write a module that displays a list of authors and the count of articles they've written? Then you can display the module anywhere on the website that you like (and modules don't normally occupy a lot of screen real-estate). J! can only load one component on a page view whereas, with a module, you can display those things [more-or-less] anywhere you want; you can even embed a module within an article ... if you want.

Von Barron
Joomla! Apprentice
Joomla! Apprentice
Posts: 6
Joined: Fri Apr 08, 2016 9:19 am

Re: Number total of articles per author

Post by Von Barron » Sat Sep 16, 2023 4:24 am

To display the list of authors, I use a menu item Contacts > List of contacts in a category.

User avatar
ceford
Joomla! Hero
Joomla! Hero
Posts: 2021
Joined: Mon Feb 24, 2014 10:38 pm
Location: Edinburgh, Scotland
Contact:

Re: Number total of articles per author

Post by ceford » Sat Sep 16, 2023 7:50 am

To elaborate on the previous replies, the query you need is something like this:

Code: Select all

SELECT a.id , (SELECT count(id) FROM `#__content` WHERE `created_by` = a.id) AS narticles FROM `#__users` AS a; 

Von Barron
Joomla! Apprentice
Joomla! Apprentice
Posts: 6
Joined: Fri Apr 08, 2016 9:19 am

Re: Number total of articles per author

Post by Von Barron » Sat Sep 16, 2023 8:40 am

Thank you!

nacc
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 131
Joined: Mon Jul 03, 2023 7:08 pm

Re: Number total of articles per author

Post by nacc » Sun Sep 17, 2023 6:33 pm

@Von Barron: There is a module on the JED that does what you want.


Post Reply

Return to “Joomla! 4.x Coding”