Wednesday, October 27, 2010

WordPress Quickies

It's been a fun day of WordPress hacking. Here a few handy take-aways:

  • Want to set a default preference for the default link type associated with an image? You can do so by following these instructions. This is also a friendly reminder that you can tweak any WordPress option by visiting: I usually do this by accessing the database directly, but this way should be faster and more convenient.
  • Is the Parent Page selector missing from the new page you're trying to add to your site? It's probably because you don't have any published pages yet. In other words, make sure the parent page you want to link to is not in draft mode.
  • Recent versions of WordPress allow a page or post to have a Featured Image. From a code perspective, it's trivial to access the selected photo. Just say something like:
    the_post_thumbnail(array(100,100), array('class' => 'alignleft'));
    and you'll get a 100x100 pixel thumbnail floated to the left. This is much easier than attachment hacks I've used in the past.
  • To access the category being displayed on a category archive page (that is, a page that returns true to is_category()) say:
     $cat = $wp_query->get_queried_object();
    It's tempting to use get_the_category(), which may appear to work. But, what you're getting with that function is the category of the most recently rendered post. The list of categories returned will contain the category being displayed, but may also contain additional, unrelated, categories as well.

What was the last WP hack you came across?

No comments:

Post a Comment