We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Count Alias extension

Development and Programming

Cocoaholic's avatar
Cocoaholic
445 posts
17 years ago
Cocoaholic's avatar Cocoaholic

This extension adds a {count_alias} and {total_results_alias} variable to the weblog tag.

You might wonder why 😉

Sometimes I wrap a weblog tag with a query tag, for example to fetch a category_id based on a url_segment. The problem with this trick is that the {count} and {total_results} variables return the values of the query tag, instead of the weblog tag inside.

In the following example {count} will always be 1:

{exp:query sql="SELECT cat_id FROM exp_categories WHERE group_id="1" AND cat_url_title = '{segment_2}' LIMIT 1"}

{exp:weblog:entries weblog="default_site" category="{cat_id}" dynamic="off"}
{count} - {count_alias}

{/exp:weblog:entries}

{/exp:query}

Of course this problem can be workd around using some PHP but then you might run into “PHP on input/output” problems, I did!

Using this extension and the {count_alias} and {total_results_alias} variables solves the problem.

Download link

Cheers!

(the same problem is true for the {switch="one|two"} variable but that one is unfortunately not accessable through an extension hook, but please correct me if I’m wrong)

       
Nicolas Bottari's avatar
Nicolas Bottari
143 posts
15 years ago
Nicolas Bottari's avatar Nicolas Bottari

Thanks! Looks like a great extension.

Would this work with a weblog tag wrapped in a categories tag? The {count} tag is the same for both, and the {count} tag in the weblog tag is therefore ignored.

I had to do this as I needed other fields besides the {title} tag, and the category archive tag wasn’t working out for me.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.