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.

Showing the total number of entries

May 19, 2009 9:56am

Subscribe [2]
  • #1 / May 19, 2009 9:56am

    morph london

    47 posts

    The code below works as I want it to, but I am sure there is a much better way of doing this if anyone has any better suggestions. I am just trying to return the total results.

    {exp:weblog:entries weblog="agency_jobs" dynamic="off" author_id="1" disable="categories|member_data|trackbacks"}
      {if count==1}
        You currently have {total_results} active Job Listings
       {/if}
    {/exp:weblog:entries}


    Thanks

  • #2 / May 19, 2009 10:57am

    Mark Bowen

    12637 posts

    Hi Alex,

    You could probably always just use a SQL query instead to get the same sort of thing. It might save you a bit on resources maybe :

    {exp:query sql="
    SELECT COUNT(*) as post_count FROM exp_weblog_titles WHERE weblog_id = '1' AND status != 'closed'
    "}
    
    {post_count}
    
    {/exp:query}

    You will need to find out the weblog_id for your agency_jobs weblog as it may not be 1 like in the example above but this is one way you could go about it perhaps?

    Hope that helps a bit.

    Best wishes,

    Mark

  • #3 / May 19, 2009 11:41am

    morph london

    47 posts

    Yeah thats great Mark, I was looking at that way. Didn’t know there was a SQL query tag, that will be pretty useful. The only thing I found was an issue was dealing with dates in a SQL query and Expression Engine. What format is it in? and how would I select the only the ones that have not expired?

    Thanks again for your help.

  • #4 / May 19, 2009 12:05pm

    Mark Bowen

    12637 posts

    Hiya,

    …how would I select the only the ones that have not expired?

    I’ve not tested this fully but I think this should work for what you need :

    <?php
    global $LOC;
    $timestamp = $LOC->now;
    ?>
    
    {exp:query sql="
                SELECT COUNT(*) as post_count
                FROM exp_weblog_titles
                WHERE weblog_id = '1'
                AND status != 'closed'
                AND expiration_date = 0
                OR expiration_date > <?php echo $timestamp; ?>
    "}
    
    {post_count}
    
    {/exp:query}

    You’ll need PHP parsing turned on for the template to Input mode for this to work.

    Hope that helps a bit.

    Best wishes,

    Mark

  • #5 / May 19, 2009 12:34pm

    Lisa Wess

    20502 posts

    Moved to How To for you.  Also check out the statistics tags.

  • #6 / May 19, 2009 12:36pm

    morph london

    47 posts

    Thats great thanks for all your help.

  • #7 / May 19, 2009 2:09pm

    Mark Bowen

    12637 posts

    Moved to How To for you.  Also check out the statistics tags.

    Darn I always forget about that one although in my defence I thought that it didn’t handle expired entries. Seems like it does though so definitely a lot easier than my query 😉

    Maybe one runs faster than the other though now I know that it does handle expired entries that’s the one I’ll be going with from now on as will save me quite a few key presses 😊

    Thanks for reminding me of that one Lisa.

    Best wishes,

    Mark

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

ExpressionEngine News!

#eecms, #events, #releases