ExpressionEngine Code Snippet: How many weblog entries have been posted in the past 24 hours?

This is a relatively simple question: how can you display how many weblog entries have been posted in the last 24 hours? It turns out there isn’t a pre-made ExpressionEngine way to do this, but if you copy and paste the code below in to your template, you can do it yourself.

{exp:query sql="SELECT COUNT(entry_date) AS entry_count FROM exp_weblog_titles WHERE (NOW() - INTERVAL 24 HOUR) < FROM_UNIXTIME(entry_date) AND status='open'"}
                
<p>Welcome to MySite.com&hellip{if entry_count == '1'}There has{if:else}There have{/if} been <a href="{path="blogs"}"><strong style="color: #FF0000;">{entry_count} new</strongblog {if entry_count == '1'}entry{if:else}entries{/if}</aposted in the last 24 hours.</p>{/exp:query} 

To prevent certain weblogs from being included in the count, add “AND weblog_id !=‘36’” - replacing “36” with your weblog_id number.

The conditionals change the wording to make sure that the sentence remains proper English grammar.

This code when viewed in a browser will result in: “Welcome to MySite.com… There have been 22 new blog entries posted in the last 24 hours.”


Posted on Mar 04, 2009 - 11:15 PM

Leave A Comment!!

Please enter the letters or word you see in the image below:

Name:

Email:

Location:

URL:

Remember this information for next time

E-mail me about follow-up comments