ExpressionEngine Count variable conflict issue in Categories and Entries Loop

Let you have categorized entries in a weblog, you want to show them category-wised, what will you do? You have to put a EE category tag loop first and then you will put entries tag loop inside category loop( Although you can handle this with query module or with raw php too), code will be something as below

{exp:weblog:categories weblog="myweblog" style="linear"}
<h2>{category_name}</h2>
	{exp:weblog:entries weblog="myweblog" category="{category_id}" limit="5" sort="asc"}
	{count}. {title}
	{/exp:weblog:entries}	
{/exp:weblog:categories}

See carefully above, this will show category name, five entries under each category. Entry title will be prefixed with
number which is suppposed to be as 1.2.3… etc, but it won’t because category loop has same variable, so if first category
has three entries, count variable will show 1 for every entry. For second category – if it has two or more entries, count will
print 2 for every entry.

To solve this issue, user {absolute_count} inside entry loop instead of {count}. It’s very common issue which can be solved very easily!

Advertisements
This entry was posted in Uncategorized. Bookmark the permalink.

2 thoughts on “ExpressionEngine Count variable conflict issue in Categories and Entries Loop

  1. Thank you! That’s an awesome tip!

    Even after using ExpressionEngine for a long time, I love the fact that you can always learn something new that EE can do. I was wondering what to do with that {count} variable inside an embedded exp:weblog:entries tag for a long time! You made my day 🙂

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s