x
 
Create New Page

Revision: Count Entries

Revision from: 13:13, 20 Jun 2007

Question:

Is it possible to get the number of entries in a set of entries?

Answer:

<head>
<?php $entry_count=0; ?> <!-- initialize a variable -->
</
head>

<
body>
<
div id="maincontent">
{exp:weblog:entries}
<?php $entry_count
++; ?> <!-- increment the variable -->
{title}
{
/exp::weblog:entries}
</div>

<
div id="sidebar">
<
p>This page lists <?php echo($entry_count); ?> entries</p> <!-- output the count -->
</
div>
</
body>

Basically, this will count the number of entries are being displayed on the page. That’s all.

This technique can of course be used to do things like number comments or entries as well (just use the entry_count variable inside the exp:weblog:entries block), and I’m sure this has been mentioned elsewhere in these forums. I’ve never seen mention of a simple counter being used as an entry tally, though, so I put it here in the event someone does a forum search for entry count.

The biggest downside of this method is that you can only use the tally after the exp:weblog:entries block, but it gets the job done rather simply otherwise.

Category:Tricks

Categories: