Reflection in the balloon…

A few awesome WordPress tuts on @WPWag
A few weeks back I decided to get back into WordPress tutorials. And since I sold @WPCult, I threw a few up on my site (and will continue too), but wanted more in depth tutorials and tricks on another domain. @WPWag came in and great posts like Adding a twitter field to comments in Hybrid & Extending the WordPress admin_body_class, just to name a few…
Extending the WordPress admin_body_class

I’m working on a new WordPress theme for release with 3.0 that includes many new post_types. One problem I found was that if I wanted to not include the editor but allow for photo uploads, the Insert into Post button would no longer appear. But I didn’t want the end user to have access to the editor. So I thought I would remove or hide the editor with CSS or DOM manipulation. One problem I noticed is the admin classes are pretty weak, so I thought to beef it up with a custom class on my post_types.
Here is the snippet to extend the WordPress admin_body_class.
function wpwag_admin_body_class( $classes ) {
global $wpdb, $post;
$post_type = get_post_type( $post->ID );
if ( is_admin() && ( $post_type == 'photo' ) ) {
$classes .= 'post_type-' . $post_type;
}
return $classes;
}
This will then output on my post_type Photo: post_type-photo. Sweet!
Don’t forget to add the correct filter:
add_filter( 'admin_body_class', 'wpwag_admin_body_class' );
Custom post type "jokes" plus my code snippet

I’ve been working on creating a custom post type for the site. Right now I’ve got one set as Jokes. Just need a few to add into those posts
.
Check out the code I am using:
/* Actions */
add_action( 'init', 'wpwag_init' );
/* Filters */
// Fire this during init
function wpwag_init() {
$supports = array( 'title', 'editor', 'thumbnail', 'trackbacks', 'custom-fields', 'comments', 'page-attributes' );
register_post_type( 'jokes',
array(
'label' => 'Jokes',
'singular_label' => 'Joke',
'public' => true,
'show_ui' => true,
'_builtin' => false,
'_edit_link' => 'post.php?post=%d',
'capability_type' => 'post',
'hierarchical' => false,
'rewrite' => array( 'slug' => 'jokes', 'with_front' => false ),
'query_var' => true,
//'taxonomies' => array( 'post_tag', 'category' ),
'supports' => $supports,
'menu_icon' => get_stylesheet_directory_uri() . '/library/css/images/joker.png',
)
);
}
While I don’t find it necessary to share a mass tutorial on how,what and why. You can check out these awesome post tutorials on the custom post types.
just to list a few..
Capturing the URL anchor with jQuery & flashing an element

Today were going to be doing a jQuery tutorial. I was searching a way to animate an element, as if to flash it on and off. But, I didn’t want this to happen on every single page load, just when a certain link was clicked from the home page.
What to do
The easiest way was to capture something from the link that was clicked. Maybe a cookie, or the URL it’s self? I decided to add an anchor of “#like” to the link. Now all I had to do was do something if, and only if the anchor was present.
How to capture the anchor
I went searching for, and found the URL plugin for jQuery which allowed me to do just that. Find elements in the URL.
A jQuery plugin to parse urls and provides easy access to information within them, such as the protocol, host, port, the segments that make up the path and the various query string values.
To do so we need to capture the variable:
var anchor = jQuery.url.attr('anchor');
This is setting the variable anchor to capture any anchor that may or may not be attached to the URL.
Then will use an if statement:
if (anchor == 'like') {
//do something
}
The above states that if the anchor of the current site’s URL is #like, do something. Be sure to omit the pound key
What are we going to do?
Well, I’m glad you asked, or I implied. If you came to this post from the home page after clicking Likes: (x) then you may have noticed the like this field flash yellow on the left sidebar. If not, you can try it now?
Well I’m capturing the #like anchor and animating the opacity of said element which has a background color of yellow. Lets check out that code:
$j('<span class="like-flash"><br /></span>')
.insertAfter( $j('.iLikeThis .counter') )
.fadeIn('normal').fadeOut('normal')
.fadeIn('normal').fadeOut('normal')
.fadeIn('normal').fadeOut('normal')
.fadeIn('normal').fadeOut('normal')
.fadeIn('normal')
.fadeOut(3000, function() {
$j(this).remove();
});
Can you figure out what’s happening? We’re just creating an element with a class, inserting it after a particular element* and fading it in and out a few times. *You don’t have to add it after a certain element, you can add it where ever you like
That’s it, lets see the whole code now:
var anchor = jQuery.url.attr('anchor');
//console.log(url); //to see what the anchor is (checking purposes)
if (anchor == 'like') {
$j('<span class="like-flash"><br /></span>')
.insertAfter( $j('.iLikeThis .counter') )
.fadeIn('normal').fadeOut('normal')
.fadeIn('normal').fadeOut('normal')
.fadeIn('normal').fadeOut('normal')
.fadeIn('normal').fadeOut('normal')
.fadeIn('normal')
.fadeOut(3000, function() {
$j(this).remove();
});
}
Adding a custom default gravatar to your site
Notice on some site’s how they’ve got a different gravatar than the usual “mystery man”? Ever wonder how that is done? Well it’s really simple.
Were going to add a few lines of code to your functions.php file:
function wag_gravatar ( $avatar_defaults ) {
$myavatar = 'full-path-to-image/wag-gravatar.png';
$avatar_defaults[$myavatar] = 'WPWag';
return $avatar_defaults;
}
That’s the whole function! I told you it was easy.
Just be sure to add the correct filter.
add_filter( 'avatar_defaults', 'wag_gravatar' );
Let’s see your default gravatar’s!
Add a twitter field to your comments in Hybrid Framework

You’ll notice that I’ve got this feature active on the site now. If you scroll down to the comments section, you, or any commenter can add his/her twitter handle that will attach to the comment.
Since I am using the Hybrid Theme, this tutorial is for it.
#1
First off, we need to grab the latest version of Twitter Link Comments. And of coarse be sure you’ve got the Hybrid Theme (version 0.8.x or greater) installed and activated. With Hybrid 0.8, you’ll need the latest trunk version of WordPress, which as of today happens to be 3.0, beta-2
#2
Ok, now that’s settled, I hope
. We can move on the the options that Twitterlink has. Below you’ll see a bases for what you need to apply. We’ll turn off auto add twitter field, and apply the style and setting to how we want the link formation to be.
#3
Next, will moving into our functions.php file located in your child theme. No child theme being used? Well at the end of this tutorial will apply this function into a plugin!
Paste this function.
function add_twitter_id_field($fields) {
$twitlink = get_option('twitlink');
$fields[] = '<p class="form-twitter"><label for="twitter">Twitter <span class="required">* <em>Don′t use the @ symbol</em></span></label><input type="text" class="text-input" name="atf_twitter_id" id="atf_twitter_id" value="' . esc_attr( $twitlink['post_html'] ) . '" size="40" tabindex="4" /></p>';
return $fields;
}
That’s it, the whole function. Now be sure to add the appropriate filter, which is:
add_filter( 'comment_form_default_fields', 'add_twitter_id_field' );
This function will filter in the new input with the ID of atf_twitter_id which the plugin Twitter Link Comments looks for to apply it’s twitter field magic.
Now, I’ve noticed that when an end user, or commenter comments multiple times that if inputting a different twitter handle the newest and latest gets applied to all previous comments. I sure there is a way around that, I’ve just not looking into it.
#done
Um, that’s a number, some times.
Anyway, that’s all you’ve got to do to add to add your users twitter handle and attach it to their comments.
Leave a comment below, and test it out!


