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.

Entry Gallery module: How to get the "total" count of all images returned

February 18, 2009 6:35am

Subscribe [3]
  • #1 / Feb 18, 2009 6:35am

    haydenp

    46 posts

    I’m busy using the Entry Gallery module and have it working successfully. The module provides the single variable {eg:count} holding the current image counter but what I would like to know is whether or not a single variable is provided holding the total number of records/images being returned? This is vital for me for applying CSS (see THIS-IS-THE-LAST-RECORD).

    Will I need to go in and modify the modules code or is this variable provided (there is no mention of it in the documentation)?

    {exp:entry_gallery:images entry_id="{entry_id}"}
    
        {if {eg:count}==1}
           <h1 class="firstImage">This is the first image</h1>
        {/if}
        
        {if THIS-IS-THE-LAST-RECORD}
            <h1 class="lastImage">This is the last image</h1>
        {/if}
    
    {/exp:entry_gallery:images}
  • #2 / Feb 18, 2009 12:54pm

    lukemcr

    154 posts

    Using EE’s Query module, it’s usually pretty easy to “create” your own variables based on database contents.

    I think this is close to what you want:

    {exp:query sql="SELECT COUNT(*) AS total_count FROM exp_gallery_entries"}{total_count}{/exp:query}

    Using the SQL above, you can use {total_count} anywhere within the {exp:query} tags to return the total number of gallery entries.

  • #3 / Feb 18, 2009 1:08pm

    haydenp

    46 posts

    Hi lukemcr

    Thanks for your reply. I thought it would have been provided by default and thought it may have simply been omitted from the user guide OR I had overlooked it.

    If not, I was thinking of editing the module so that it was returned as a single variable, but I think your method would be easier ... many thanks!

  • #4 / Feb 18, 2009 1:15pm

    lukemcr

    154 posts

    No problem. If you put the beginning and ending {exp:query} tags at the very beginning and ending of your template, you can use your SQL query variables anywhere in the template.

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

ExpressionEngine News!

#eecms, #events, #releases