ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

{count} variable is not counting inside weblog:entries loop

August 18, 2009 10:12am

Subscribe [3]
  • #1 / Aug 18, 2009 10:12am

    sthmtc

    11 posts

    {count} is not counting, instead it renders “1” for every entry. below is the code i’m using in the page template, with a bit of context in case it has something to do with the query module… any help would be highly appreciated!

    {exp:weblog:categories style="linear" weblog="{segment_1}"}
    {if segment_2==category_url_title}
    
    {exp:query sql="SELECT count(exp_category_posts.entry_id) AS post_count FROM exp_category_posts WHERE exp_category_posts.cat_id = {category_id} "} 
    
        {exp:weblog:entries weblog="{segment_1}" category="{category_id}" status="not footer" search:publications_partof="not y"}
    
            {count}
    
        {/exp:weblog:entries}
    
    {/exp:query}
    
    
    {/if}
    {/exp:weblog:categories}

    Moved to HowTo by Moderator

  • #2 / Aug 18, 2009 10:37am

    Sue Crocker

    26054 posts

    What are you using post_count for?

  • #3 / Aug 18, 2009 11:38am

    sthmtc

    11 posts

    To be honest: I don’t know why it’s there. I copied the query from the knowledge base or something. On further investigation, it shows that {count} is rendering “1” for _every_ article in the _first_ category, “2” for _every_ article in the _second_ category, and so on…

    Alsmost as if {count} is being “hijacked” by the categories loop?!

  • #4 / Aug 18, 2009 12:40pm

    Ingmar

    29245 posts

    Alsmost as if {count} is being “hijacked” by the categories loop?!

    That’s exactly what’s happening.

  • #5 / Aug 18, 2009 12:44pm

    sthmtc

    11 posts

    So is there any way I can still count the weblog entries being rendered on the page?

  • #6 / Aug 18, 2009 12:48pm

    Sue Crocker

    26054 posts

    What happens if you use {post_count} instead?

  • #7 / Aug 18, 2009 12:57pm

    sthmtc

    11 posts

    With {post_count} I’m getting something like “7” for every entry or, “10”, depending on which category I’m viewing. Can’t see any pattern, though. At first I thought it was the “total amount of entries +1” but it isn’t. Don’t know what it really renders then…

  • #8 / Aug 18, 2009 3:24pm

    Ingmar

    29245 posts

    I am afraid you are running into scope issues here. Your best option is probably a line or two of PHP, creating your own counter, as it were. Let me know if you want to go down that route and I can move this thread to Howto for you.

  • #9 / Aug 19, 2009 11:12am

    sthmtc

    11 posts

    Yes please. Of course I like to go down that route if there isn’t any other option. I tried to build my own counter but I’m running into scope issues as well, I guess. So if anyone could assist that would be highly appreciated.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases