Code Explosion – Week 6

Posted on: January 6th, 2012

Resolutions

Happy New Year! I hope you had a wonderful holiday and got some major work done. I realize I have been negligent with the “Weekly” portion of this blog series, and one of my New Year’s Resolutions was to remedy that. So here it is, WEEKLY CODE EXPLOSION – WEEK 6…FOOM PACCKKOWWWW PCKKRRREEWWW [explosion noises].

WordPress

For a site I’ve been working on, I needed to load query_posts for a specific date range. After digging around, I found this piece of neatness in the WordPress forums. The link for the full thread is here.

<?php
  function filter_where($where = '') {
    //posts in the last 30 days
    //$where .= " AND post_date > '" . date('Y-m-d', strtotime('-30 days')) . "'";
    //posts  30 to 60 days old
    //$where .= " AND post_date >= '" . date('Y-m-d', strtotime('-60 days')) . "'" . " AND post_date <= '" . date('Y-m-d', strtotime('-30 days')) . "'";
    //posts for March 1 to March 15, 2009
    $where .= " AND post_date >= '2009-03-01' AND post_date <= '2009-03-15'";
    return $where;
  }
add_filter('posts_where', 'filter_where');
query_posts($query_string);
?>

Contact Form 7

A week ago, a client needed to redirect to a thank you page after form submission. I’d been using the super simple Contact Form 7 to handle the form work, but there wasn’t a direct checkbox to make this happen. A few google searches later I came across this code on the Contact Form 7 main site.

on_sent_ok: "location = 'http://example.com/';"

Add the above code to the ‘Additional Settings’ box at the bottom of your Contact Form 7 editor and accepted form submissions will redirect the user to whatever page you want.

@font-face

With one of the agencies I’ve been working for, I launched a site yesterday. I was using a very specific font-face that had tested well and had proved no issue at any point in the testing phase. Much to my, and my boss’s dismay, Firefox rendered our @font-face as Comic Sans. [Insert favorite Comic Sans statement here] After doing a bit of research, we found out it was undoubtedly a server issue, an issue that was confirmed when I came across this article from CSSBakery.

After plugging int he following code to my .htaccess file, Firefox rendered my font correctly and got my blood pressure back down to normal. If you encounter the problem I described, just open up your .htaccess file and drop the following code in.

AddType application/vnd.ms-fontobject .eot
AddType font/ttf .ttf
AddType font/otf .otf
<FilesMatch ".(ttf|otf|eot)$">
<IfModule mod_headers.c>
Header set Access-Control-Allow-Origin "*"
</IfModule>
</FilesMatch>

WordPress Plugins

If you haven’t checked it out yet, go right away to MaxButtons.com. Max Foundry released this awesome CSS3 button WordPress plugin this past week and copies have been flying out like crazy. I helped create several of the button packs so go support Max Foundry and myself by getting the plugin. There is much greatness to behold in Max Buttons Pro.

Link Roundup

These are some of the top links I added to my Delicious bookmarks.

  1. @font-face Gotchas – Paul Irish
  2. TableSorter – jQuery Plugin
  3. 40+ Must-Have Cheat Sheets For Web Designers

previous post: WordPress Menus, Sidebars and Widgets next post: PeterfySPN