Display Author Gravatar in the Loop

If you want to display an author’s Gravatar, this little code should do the trick (note that it only works inside the Loop):

<?php echo get_avatar( get_the_author_meta('user_email'), 48 ); ?>

The second parameter dictates the size of the avatar. More about get_avatar().

The Disappearing Meta Value Issue

I’ve been using this Tutplus tutorial to create custom post types, especially the part about creating custom post input. It works nicely, except for the fact that the meta values entered with that input can get deleted completely by WordPress when it autosaves a post. Or if you Quick Edit a post.

It seems to be a WordPress bug Fortunately, someone posted a fix on the comment area. It’s pretty self-explanatory.

There’s also a Trac ticket discussing it, there you can find a more correct fix involving the use of nonces.

How to Get your Post Thumbnail’s Width and Height

In Settings > Media, you are able to set only the height or width of the Thumbnail images and WordPress will resize them proportionally (i.e.: if you have a fixed height, then the widths will vary depending on your uploaded image dimension, and vice versa).

Inside the loop, you can get a thumbnail’s width, height and URL using this code:

$imgdata = wp_get_attachment_image_src( get_post_thumbnail_id(), 'thumbnail' );
$imgurl = $imgdata[0]; // the url of the thumbnail picture
$imgwidth = $imgdata[1]; // thumbnail's width
$imgheight = $imgdata[2]; // thumbnail's height

For the second parameter of the wp_get_attachment_image_src function you can also use ‘medium’, ‘large’ and ‘full’. They correspond to the dimension for the other sizes in Settings > Media.

Read more about the wp_get_attachment_image_src function.

WordPress 3.0 Theme Development Links

These are some of the best, currently available resources on the various WordPress 3.0 features relevant to theme development. I’ve been using and growing this list personally for a while as a sort of launchpad and they should be enough for most development needs.

There are plenty other resources, tutorials, and tips out there that I do not include here, though. For that, Google is your friend.

Menu

Custom Post Types

Custom Taxonomies

Multisite

Custom Header and Background

Editor Styles

New Theme Template Files

Miscellanea

Understand Child Themes, Hooks, Actions and Filters in Five Minutes

What on earth are they?

Example time. A theme you like uses <h2> tag for post titles. You hate that and want <h1> instead.

The old, boring way is you open the theme files, starting from index.php, changing all <h2> tag to <h1>, then moving to the other files: archives.php, tag.php, category.php, doing the same thing over and over again, hoping you don’t miss anything.

Gah!

That is not clever because a) it’s too much work, and b) when the theme is updated, you’re screwed.

Wouldn’t it be better if you could just a) write the change once, have it applied globally, while b) at the same time not modifying the theme’s code?

Yes. Yes of course. And you can do just that by mastering the art of child theming, Hooks, Actions and Filters.

Enter Child Theme

Child theme is a lazy developer’s best friend.

A child theme is everything its parent is, except for the changes you add that make it awesome-er.

When you use a child theme, WordPress will check whether it has the usual PHP files. You know, index.php, header.php, the likes. If your child theme has it, great, WordPress will happily use it. If not, WordPress will smile at it knowingly and use its parent’s files instead.

BAM! Now you understand how parent-child theme works in WordPress.

Every theme can be a parent theme, but some are especially kind and beneficial to their children. They are usually known as theme frameworks. Ever heard of them?

They make the best parents for various reasons (good coding practice, built-in SEO), but in this case it is because they have hooks aplenty.

Hooks, Filters, Actions!

Hooks are marked places on a theme. The start of the comment area. The post meta. And so on.

Actions and Filters are the things you can do at those places.

Actions do stuff. Like showing a picture of kitten after your post title. Filters specifically deals with modifying texts (or HTML, same thing). Words go into your Filter and come out differently. Profanities get Filtered into ****s. <h2>s to <h1>s.

Let’s repeat that.

Hooks: places. Actions: doing things. Filters: changing texts.

Theme frameworks are smart because they are made to be modified. Those clever guys and girls who wrote them know that you want to add stuff between your post title and content, that you want to change the wordings on your comment forms, so they add tons of useful hooks in their frameworks for you to use in your child theme.

Hooks are provided by the parent theme. Actions and Filters you write yourself in your child theme’s functions.php.

And that is all.

Recap

Think of an awesome theme to create. Or a neat feature to add. Use a theme framework as a parent. Create a child theme. Use parent’s Hooks to add Actions and Filters. Joy.

Further reading

Once you grasp the concept, visit these places to learn the technical sides.

How To Modify WordPress Themes The Smart Way by Ian Stewart. Explains all of these concepts with easy to follow examples.

Adding Custom WordPress Hooks by Benedict Eastaugh. For when you want to create your own theme framework.

Plugin API : Hooks, Actions and Filters at the WordPress Codex. Plugin? Yeah. Hooks, Actions and Filters were initially features that has to do with plugin creation.

Theme Options UI: Consistency Matters!

Just tweeted this:

Doing it right: #genesiswp ‘s theme options UI mimics WP’s look instead of having its own fancy UI.

Consistency Matters

A lot of you must have seen how various WordPress themes have different theme options UI design. Most of them opt for pretty looking options page with labels, inputs, buttons, icons, and forms that look wildly different from the rest of the Dashboard.

If your theme is like that, you’re doing it wrong.

Huh? Why?

Tutorial: Using jQuery Masonry with WordPress

This is a short tutorial on integrating Masonry, the jQuery layout plugin, with your WordPress site. We will try to use that jQuery plugin to show a list of posts in a neatly stacked layout, similar to the one I have down here. Here’s an explanation about Masonry, from it’s home page:

Think of it as the flip side of CSS floats. Whereas floating arranges elements horizontally then vertically, Masonry arranges elements vertically then horizontally according to a grid. The result minimizes vertical gaps between elements of varying height, just like a mason fitting stones in a wall.

Here’s a visual explanation, which I took and edited to fit my layout. Pay attention to the numbers, which shows the order of the elements in your HTML code:

Read the rest of this tutorial→

Page 1 of 912345...Last »

Latest Links More →

Custom Shortlinks for WordPress

Have your own short domain name for the purpose of shortlinking? Here’s an easy way to combine that with your WordPress install.

The Quick Start Guide to Using Google Webmaster Tools With WordPress

GWT is a great, frequently updated features like showing you search queries volume, malware and crawl error diagnostics and links to your site. If you don’t use it yet, you probably need to. This will help you get started.

WordPress & jQuery Contact Form without a Plugin

I would recommend this either if you want more flexibility or to learn how to code a contact form.

Understanding and cleaning the pharma (spam) hack on WordPress

How to fix that hack:

This attack is very interesting because it is not visible to the normal user and the spam (generally about Viagra, Nexium, Cialis, etc) only shows up if the user agent is from Google’s crawler (googlebot). Also, the infection is a bit tricky to remove and if not done properly will keep reappearing.

Web Safe Fonts Cheat Sheet

An updated (written in April 2010), well researched, CC-licensed Web safe fonts cheat sheet, available both in low-res PNG and high-rest PDF. Even the article is useful as well.

The Nicest 2010 Child Theme You’ll See Today

The Timaru Mental Health Support Trust website, made for charity by Team USA (comprised by web superstars like Jason Santa Maria, Dan Mall, Liz Danzico and Automattic’s John Ford) during the FullCodePress competition, is actually a clever child theme of 2010.

More recap by JSM, Daniel Mall, and Liz Danzico.

WordPress 3.0 Theme Tip: The Comment Form

The simpler way to code comment form (once you understand how hooks and filters work).

Showing and hiding content with pure CSS3

I like it, I think it’s short and easy to understand.