Hi Craig,
$blogMetaData['totalRecords'] provides a count of all records returned from getRecords.
Modifying your existing code, you can run a query inside the following foreach loop to get counts for each Year/Month archive.
Try changing this:
<?php foreach($months as $date => $name): ?>
<li><a href="blog.php?createdDate_keyword=<?php echo "$date";?>" ><?php echo $name;?> <?php echo $year;?><span><?php echo $blogMetaData['totalRecords']; ?></span><i class=" icon-right-open"></i></a></li>
<?php endforeach ?>
To this:
<?php foreach($months as $date => $name): ?>
<?php $archiveMonthCount = mysql_count('blog', "`createdDate` LIKE '$date%'"); ?>
<li><a href="blog.php?createdDate_keyword=<?php echo "$date";?>" ><?php echo $name;?> <?php echo $year;?><span><?php echo $archiveMonthCount; ?></span><i class=" icon-right-open"></i></a></li>
<?php endforeach ?>
mysql_count is an internal CMSB function that returns the number of records found. For the WHERE clause, we're searching createdDate using the LIKE operator with wildcard % on your $date string (ex. 2023-09). This will match createdDate fields starting with your $date string value.
Hope this helps!
Best,
Steve