Query Debug Info plugin

query_debug_info_query

I wanted to have this plugin when I was beginning with WordPress and I did have to use multiple loops in one template.

This simple plugin adds some overlay tabs in the left side of the screen with information about the constants of the theme like (WP_CONTENT_DIR, WP_PLUGIN_DIR, TEMPLATEPATH, STYLESHEETPATH, etc..) and infomation useful to debug your loops like the of type you are currently viewing, the query results (post_count, found_posts), the query vars used and the query used (the raw SQL generated by WordPress.

How to use this plugin

After activating the plugin you can add the function call in your template to display information about the main query:

<?php if (function_exists(‘debuginfo’)) { debuginfo(“Main”); }?>

Add additional calls after creating a new WP_Query object, if you want to track a specific variable you can pass it to the function, example:

<?php $my_query = new WP_Query(“showposts=3&category_name=Featured&order=DESC”); ?>
<?php if (function_exists(‘debuginfo’)) { debuginfo(“Secondary”,2,$my_query); }?>

The information is only displayed if you are logged in as an administrator.

More screenshots of this plugin and the download link in the Query debug info page or you can download it from the Query debug info page in wordpress.org

Bitly shared links plugin

This will be the first plugin I will publish, so it will be a little simple and maybe unpolished.

I built this plugin because I see that all the links posted in twitter are shortened by bit.ly or a similar service. There are many plugins that insert at the bottom of the posts links to share the post in various services but the link sent is not shortened. By default a long URL sent to twitter is shortened using bit.ly but one of the useful features of bit.ly is that you can get statistics of how many clicks the shortened URL received, from where and when.

How to use it:

bitly_share_links_optionsOnce you have installed and activated the plugin you have to enter your login and bit.ly API key in the ‘Bit.ly Share Links Options’ page and select what short URL you want to use (bit.ly or j.mp) and if you want the links to open in a new window/tab.

Now when you publish a new post the plugin will send a request to bit.ly to generate the short URL and store it in the post meta. When a user goes to the post page at the bottom of the post the plugin will insert links to share your posts in the most popular social media sites (facebook, twitter, stumbleupon, etc..).

bitly_share_links_post_editIf you have the sociable plugin installed the plugin will not display a second set of links, instead it will hook into the sociable plugin and replace the long URL with the short url generated by bit.ly.

The plugin also retrieves the stats for the short URL, you can see the stats in the edit post page.

Download Bitly shared links

Display the post image with your posts excerpts

You spent hours looking for that image that perfectly illustrates your post, but on the main blog page you only display the excerpt. All that work and the impact of the image is lost because the image is only displayed when the reader is viewing the full post.

You can add this function to your theme functions.php to display the thumbnail image of your post or a default image if the post does not have one.

function postimage($width,$height, $text, $class) {
$scriptpath = get_stylesheet_directory_uri();
$attachments = get_children(array(‘post_parent’ => get_the_ID(), ‘post_type’ => ‘attachment’, ‘post_mime_type’ => ‘image’, ‘orderby’ => ‘menu_order’));
if (!is_array($attachments)) {
$image = $scriptpath.”/images/default.jpg”;
echo ‘<img class=”‘.$class.’” title=”‘.$text.’” src=”‘.$scriptpath.’/scripts/timthumb.php?w=’.$width.’&h=’.$height.’&zc=1&q=100&src=’.$image.’” alt=”‘.$text.’” width=”‘.$width.’” height=”‘.$height.’” class=”‘.$class.’” />’;
} else {
$img = array_shift($attachments);
$imagelink = wp_get_attachment_image_src($img->ID,’full’);
$image = $imagelink[0];
echo ‘<img class=”‘.$class.’” title=”‘.$text.’” src=”‘.$scriptpath.’/scripts/timthumb.php?w=’.$width.’&h=’.$height.’&zc=1&q=100&src=’.$image.’” alt=”‘.$text.’” width=”‘.$width.’” height=”‘.$height.’” class=”‘.$class.’” />’;
}
}

How to use it:
In your template add the function before the call to the_excerpt.

<? postimage(100,75,”image for: “.get_the_title(),’image’)?>
<? the_excerpt(); ?>

The parameters are:
$width & $height – the purpose of these is obvious
“image for: “.get_the_title() – This will become the title and alt text of the image in the tag
image – this is the class for the tag, with this you can align/float the image to the left/right or apply any style you already defined for the images

This function uses the timthumb script to resize and crop the image automatically. after downloading the script, create a subdirectoy named ‘scripts’ in your theme directory and copy the timthumb.php file to it. Now create a ‘cache’ subdirectory in your theme directory and assign it write permissions, so the script can create the images in that directory and skip the creation of the image on every page request.

If your post does not have an image, the function will display a default image. to define the default image upload the image you want to be used by default to your theme in the images directory and name it ‘default.jpg’