Archive for the ‘Wordpress’ Category
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:
/wp-content/plugins/the-events-calendar/the-events-calendar.class.php
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( ) { add_meta_box( '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'); ?>
Da Categorie(s): Code, Custom Post Types, Plugins, Wordpress
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:
/wp-content/plugins/contact-form-7/modules/text.php
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:
/wp-content/plugins/contact-form-7/modules/textarea.php
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
Comments Off on 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!
Da Tag(s): cms, content management system, functions, php, techniques Da Categorie(s): Wordpress
Change the Status of all WordPress Posts
Comments Off on 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');
Google’s Matt Cutts SEO Video Presentation
Comments Off on Google’s Matt Cutts SEO Video Presentation
Okay, so if you’ve ever heard of Search Engine Optimization, or SEO, then you know all about Google. Let’s face it, even if you have no idea what SEO is, there is no way you’ve been able to escape the long-reaching arms of Google. If you have some spare time, an hour or so, give this video by Matt Cutts a watch. He’s a Google genius and has lots of good advice and food for thought to offer…
Da Categorie(s): Search Engine Optimization (SEO), Wordpress