The Events Calendar and Custom Post Types

The Events Calendar plugin is outstanding for tracking events within WordPress sites and blogs. The integration of templates into your own theme means you don’t risk overwriting updates each time you upgrade the plugin. This is probably the strongest event calendar plugin we’ve used, but that doesn’t mean there aren’t some tweaks that could be made. Unfortunately, all events are listed as regular posts in WordPress; this works fine, but if you’re a neat-freak like we are, you like to have everything in its own place using custom post types. Because The Events Calendar doesn’t support custom post types (yet), we have to force it a little. It’s actually pretty easy and only take a little bit of code to complete, check it out below.

On line 1029 of this file:

Replace this:

public function addEventBox( ) {
add_meta_box( 'Event Details', __( 'The Events Calendar', 'Events_textdomain' ),
array( $this, 'EventsChooserBox' ), 'post', 'normal', 'high' );

With this:

public function addEventBox( ) {
'Event Details', __( 'The Events Calendar', 'Events_textdomain' ),
array( $this, 'EventsChooserBox' ), 'post', 'normal', 'high' );
add_meta_box( 'Event Details', __( 'The Events Calendar', 'Events_textdomain' ),
array( $this, 'EventsChooserBox' ), 'events', 'normal', 'high' );

The word “events” on line 6 is the name of your custom post type. We use “events” because, well, they are events.

Now that the events are showing in your custom post types, you’ll need to edit the events templates, these are kept in the “events” directory within your theme. All you need to do is tweak the query to pull the custom post type, so add the following line of code right before the loop starts:

<?php query_posts('post_type=events&category_name=events&eventDisplay=upcoming'); ?>

Contact Form 7 Clear Default Value

Contact Form 7 is one of our favorite form plugins because its updated regularly and there are a ton of extensions you can install that make the user-experience that much more rewarding; our favorite is the Database Extension.  One feature that people have been asking about for quite some time is the ability to clear the default value of a field onClick or onFocus.  This can be done easily by changing a couple lnes of code in the plugin, but remember, when you upgrade Contact Form 7, you’ll need to reapply this change.

On line 89 in this file:

Replace this:

$html = '<input type="text" name="' . $name . '" value="' . esc_attr( $value ) . '"' . $atts . ' />';

With this:

$html = '<input type="text" name="' . $name . '" value="' . esc_attr( $value ) . '"' . $atts . ' onfocus="if(this.value==\'';
$html = $html . esc_attr( $value ) . '\') this.value=\'\';" onblur="if(this.value==\'\') this.value=\'' . esc_attr( $value ) . '\';" />';

And on line 88 in this file:

Replace this:

$html = '<textarea name="' . $name . '"' . $atts . '>' . esc_html( $value ) . '</textarea>';

With this:

$html = '<textarea name="' . $name . '"' . $atts . ' onblur="if (this.value == \'\') {this.value = \'' . esc_html( $value ) . '\';}" onfocus="if (this.value == \'' . esc_html( $value ) . '\') {this.value = \'\';}">' . esc_html( $value ) . '</textarea>';

With those 2 tweaks you should be able to clear the default value each time the user clicks the text field or text area.

Custom Post Types

Okay, if you’re not impressed with WordPress yet, you’ve got to take alook at 3.0. The development team has really made some significant updates for power users. Those who love to develop wordpress sites, like we do, you’re gonna love having the ability to create your won custom post types.

To implement this most excellent feature, just paste the following into your themes functions.php file and tweak to your delight.

register_post_type('products', array(
	'label' => __('Products'),
	'singular_label' => __('Products'),
	'public' => true,
	'show_ui' => true,
	'capability_type' => 'post',
	'hierarchical' => false,
	'rewrite' => false,
	'query_var' => false,
	'supports' => array('title', 'editor', 'author')

Can’t get much easier than that. Having this ability will allow us, as Wrodpress developers, to create more custom user interfaces for the content management systems we produce. Have fun with it!

Social Bookmarking Link Codes

How many times have you been building a custom WordPress theme and had to search for the appropriate social bookmarking link needed for your design? Well, search no more, you’ll find all the major players below:

Blinklist;Url=<?php the_permalink(); ?>&amp;Title=<?php the_title(); ?>

Delicious<?php the_permalink(); ?>&amp;title=<?php the_title(); ?>&amp;notes=<?php the_excerpt(); ?>

Design Bump<?php the_permalink(); ?>&amp;title=<?php the_title(); ?>

Design Float<?php the_permalink(); ?>&amp;title=<?php the_title(); ?>

Design Moo<?php the_permalink(); ?>&amp;title=<?php the_title(); ?>

Digg;url=<?php the_permalink(); ?>&amp;title=<?php the_title(); ?>&amp;bodytext=<?php the_excerpt(); ?>

Diigo<?php the_permalink(); ?>&amp;title=<?php the_title(); ?>

Dzone<?php the_permalink(); ?>&amp;title=<?php the_title(); ?>

Facebook<?php the_permalink(); ?>&amp;t=<?php the_title(); ?>

Fark<?php the_title(); ?>&amp;u=<?php the_permalink(); ?>

Friendfeed<?php the_title(); ?>&amp;link=<?php the_permalink(); ?>

Google Bookmarks;bkmk=<?php the_permalink(); ?>&amp;title=<?php the_title(); ?>&amp;annotation=<?php the_excerpt(); ?>

Hacker News<?php the_permalink(); ?>&amp;t=<?php the_title(); ?><?php the_permalink(); ?>

Linked In;url=<?php the_permalink(); ?>&amp;title=<?php the_title(); ?>&amp;summary=<?php the_excerpt(); ?>

Live Favorites;url=<?php the_permalink(); ?>&amp;title=<?php the_title(); ?>

Mister Wong<?php the_permalink(); ?>&amp;bm_description=<?php the_title(); ?>

Mixx<?php the_permalink(); ?>&amp;title=<?php the_title(); ?>

MySpace<?php the_permalink(); ?>&amp;t=<?php the_title(); ?>

Netvibes<?php the_title(); ?>&amp;url=<?php the_permalink(); ?>

Newsvine;save?u=<?php the_permalink(); ?>&amp;h=<?php the_title(); ?><?php the_permalink(); ?>&amp;title=<?php the_title(); ?>&amp;body=<?php the_excerpt(); ?>

Posterous<?php the_permalink(); ?>&amp;title=<?php the_title(); ?>&amp;selection=<?php the_excerpt(); ?>

Propeller<?php the_permalink(); ?>

Reddit<?php the_permalink(); ?>&amp;title=<?php the_title(); ?>

Slashdot<?php the_title(); ?>&amp;url=<?php the_permalink(); ?>

Sphere<?php the_permalink(); ?>&amp;title=<?php the_title(); ?>

Sphinn;m=submit&amp;link=<?php the_permalink(); ?>

StumbleUpon<?php the_permalink(); ?>&amp;title=<?php the_title(); ?>

Technorati<?php the_permalink(); ?>

Tipd<?php the_permalink(); ?>

Tumblr;u=<?php the_permalink(); ?>&amp;t=<?php the_title(); ?>&amp;s=<?php the_excerpt(); ?>

Twitter<?php the_title(); ?> - <?php the_permalink(); ?>

Yahoo Bookmarks<?php the_permalink(); ?>&amp;t=<?php the_title(); ?>

Yahoo Buzz<?php the_permalink(); ?>&amp;submitHeadline=<?php the_title(); ?>&amp;submitSummary=<?php the_excerpt(); ?>&amp;submitCategory=science&amp;submitAssetType=text

Change the Status of all WordPress Posts

We recently worked on a project where the client had a blog they wanted reskinned to match a new site design.  During development, they decided to start this blog from scratch with all new posts, but they still wanted to keep the older posts just in case they needed to reference them at some point.  This can be done fairly easily via the database, and here it the SQL to do it:

update wp_posts set post_status = replace(post_status, 'publish', 'draft');
update wp_posts set post_status = replace(post_status, 'inherit', 'draft');