How to display number of published articles in Joomla 3.x

I don’t know how much use will be for this code, but I thought I will share it with you. Today I needed to display the number of published articles on a Joomla website, and I used the following code:


$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->where($db->quoteName('state')." = 1");
$count = $db->loadResult();
echo 'Numer of articles:' . $count;


What this code actually does is: it is connection to the database, starting a query and counts all the rows with state = 1 (published) from the _content table. Once the query is finished, outputs the value of the total number of published articles.

Place this code anywhere in your template and customize it if you want. I did the following customization:


echo '<div class="well">Number of published articles:<strong>' . $count . '</strong></div>';


Instead of plain text, this is the result I got:

number of published articles joomla

If you have a more elegant way to display the number of published articles on the Joomla front-end please let me know in the comments.

Leave a Comment

Your email address will not be published. Required fields are marked *