tips icon image

EE Insider Tips
Sponsored by EE Screencasts

ExpressionEngine mini-howtos created by the EE Insider community.

Validating monthly archive URLs, exceptional SEO and clever titles.

User's avatar
  • Posted by Leevi Graham
  • June 09, 2009
  • 9 people have found this tip helpful.
<!-- Validate monthly archive URLS like /blog/archive/02/2009 and display blog posts -->

<!--
    
Validate the URL using the query module.
    
Users cannot have crazy urls like /blog/archive/13/2009
    Assign a couple of nice variables 
for titles meta
-->
{exp:query sql="SELECT
    DATE_FORMAT('{segment_3}-{segment_4}-01', '%M') as q_archive_month_title,
    DATE_FORMAT('{segment_3}-{segment_4}-01', '%m') as q_archive_month,
    DATE_FORMAT('{segment_3}-{segment_4}-01', '%Y') as q_archive_year
"
}

<!-- BlankMust be a bad URL get out of here -->
{if q_archive_month == "" || q_archive_year == ""} {redirect="404"} {/if}

<!-- Load up the weblog info -->
{exp:weblog:info cache="yes" refresh="60" weblog="Blog"}
<!--
    
Pass the values to the header include.
    
Why not use LG Better Metahttp://tinyurl.com/lg-better-meta
-->
{embed="_includes/.head"
    
meta_title "{q_archive_month_title} {q_archive_year}"
    
meta_title_suffix "{blog_title} Archives"
    
meta_description "{q_archive_month_title} {q_archive_year} {blog_title} Archives | {blog_description}"
    
robots_index="n"
}
{
/exp:weblog:info}
<h1>{q_archive_month_title} {q_archive_year} <small>- Monthly archive</small></h1>
<
ol>
    <!-- 
Actually output the entries -->
    
{exp:weblog:entries
        cache
="yes"
        
disable="category_fields|custom_fields|member_data|pagination|trackbacks"
        
dynamic="off"
        
refresh="10"
        
rdf="off"
        
status="not closed|Pending"
        
weblog="blog"
        
year="{q_archive_year}"
        
month="{q_archive_month}"
    
}
    {if no_results}
    
<li class="no-results">There were no posts published in {q_archive_month_title} {q_archive_year}.</li>
    
{/if}
    
<li>{title}</li>
    
{/exp:weblog:entries}
</ol>
{/exp:query} 
Justin Long04:03 on 06.09.2009

That is a super nifty script. Next time I update my archives I will be sure to add it

Add Your Comment?

You must have an EE Insider account to post comments on Insider Tips. It's fast, easy and hassle-free.

Sign up now (or login).

Search EE Insider Tips
Sponsored By