Top 10 WordPress Hacks from October 2009

How to: Show parent page title regardless of what subpage you are on

Let’s start with a nice code for those using WordPress as a CMS: Just paste it anywhere on your theme files and it will display the parent page title.

<?php
if($post->post_parent) {
    $parent_title = get_the_title($post->post_parent);
    echo $parent_title;
} else {
    wp_title('');
}
?>

» Source: http://www.wprecipes.com/how-to-show-parent-page-title-regardless-of-what-subpage-you-are-on


WordPress hack: Automatically insert author bio on each post

When you’re owning a multi-writers blog, it is important to show who wrote the post. In case of guest bloggers, it is also a nice way to give credit.
Simply insert the following lines of code into your functions.php file, and that’s all. Author bio will be automatically displayed after each post.

function get_author_bio ($content=''){
    global $post;

    $post_author_name=get_the_author_meta("display_name");
    $post_author_description=get_the_author_meta("description");
    $html="<div class='clearfix' id='about_author'>\n";
    $html.="<img width='80' height='80' class='avatar' src='http://www.gravatar.com/avatar.php?gravatar_id=".md5(get_the_author_email()). "&default=".urlencode($GLOBALS['defaultgravatar'])."&size=80&r=PG' alt='PG'/>\n";
    $html.="<div class='author_text'>\n";
    $html.="<h4>Author: <span>".$post_author_name."</span></h4>\n";
    $html.= $post_author_description."\n";
    $html.="</div>\n";
    $html.="<div class='clear'></div>\n";
    $content .= $html;
    }

    return $content;
}

add_filter('the_content', 'get_author_bio');

» Source: http://aext.net/2009/10/wordpress-hack-anything-can-be-added-anywhere-in-the-post-content/


Compress WordPress output and speed your blog’s load speed

Is your host slow? Althought on WpWebHost we don’t have that kind of problems, if you’re hosted elsewhere you’ll probably enjoy this tip who can reduce your blog load speed.

After you made sure that the zlib php extension is enabled by your hosting provider, place the following code in your header (above the DOCTYPE), save the file and your blog will load faster.

<?php
ini_set('zlib.output_compression', 'On');
ini_set('zlib.output_compression_level', '1');
?>

» Source: http://www.wprecipes.com/compress-wordpress-output-and-speed-your-blogs-load-speed


Display registered users comment count on your WordPress blog

If your blog is private or have lots of registered users, it may be interesting to be able to display the number of comments posted by registered users. Just paste this code and the count will be displayed where you pasted it.

<?php
global $wpdb;
$where = 'WHERE comment_approved = 1 AND user_id <> 0';
$comment_counts = (array) $wpdb->get_results("
		SELECT user_id, COUNT( * ) AS total
		FROM {$wpdb->comments}
		{$where}
		GROUP BY user_id
	", object);
foreach ( $comment_counts as $count ) {
  $user = get_userdata($count->user_id);
  echo 'User ' . $user->display_name . ' comment count is ' . $count->total . '
';
}
?>

» Source: http://www.wprecipes.com/display-registered-users-comment-count-on-your-wordpress-blog


Automatically resize pictures on your WordPress blog

You know it, a picture is worth a thousand words. But pictures means that you have to resize it, which is alwyas boring.
Happilly, a very cool script called TimThumb can resize pictures for you. The function below create a WordPress shortcode that will make Timthumb use even easier.

function imageresizer( $atts, $content = null ) {
	return '<img src="/timthumb/timthumb.php?src='.$content.'&w=590" alt="" />';
}

add_shortcode('img', 'imageresizer');

Then, you can use the following syntax to add an automatically resized image to your blog post:

[img]http://www.yoursite.com/yourimage.jpg[/img]

» Source: http://www.wprecipes.com/automatically-resize-pictures-on-your-wordpress-blog


WordPress tip: Create a Tweetmeme “Retweeet” shortcode

Twitter is one of the best way to get quality traffic to your blog. In order to help people sharing your articles on Twitter, you should definitely implement a Tweetmeme button, which display how many time time people RT’d your blog posts.
Just paste the function below into your functions.php file.

function tweetmeme(){
	return '<div class="tweetmeme"><script type="text/javascript" src="http://tweetmeme.com/i/scripts/button.js"></script></div>';
}
add_shortcode('tweet', 'tweetmeme');

Once you saved the file, you’ll be able to display the Tweetmeme “retweet” button anywhere on your posts. In WordPress editor, make sure you are in HTML mode and insert the following:

[tweet]

When your post will be published, the shortcode will be replaced by the TweetMeme button.
For a “Live Demo” of this tip, just take a look at my new blog Cats Who Blog, dedicated to blogging/make money online tips.
» Source: http://www.wprecipes.com/wordpress-tip-create-a-tweetmeme-retweeet-shortcode


WordPress trick: function to get tags related to category

Do you ever wanted to be able to get tags related to one (or more) specific category? If yes, I’m pretty sure you’ll be delighted with this very cool tip.
First, here is the function you have to paste in your functions.php file:

function get_category_tags($args) {
	global $wpdb;
	$tags = $wpdb->get_results
	("
		SELECT DISTINCT terms2.term_id as tag_id, terms2.name as tag_name, null as tag_link
		FROM
			wp_posts as p1
			LEFT JOIN wp_term_relationships as r1 ON p1.ID = r1.object_ID
			LEFT JOIN wp_term_taxonomy as t1 ON r1.term_taxonomy_id = t1.term_taxonomy_id
			LEFT JOIN wp_terms as terms1 ON t1.term_id = terms1.term_id,

			wp_posts as p2
			LEFT JOIN wp_term_relationships as r2 ON p2.ID = r2.object_ID
			LEFT JOIN wp_term_taxonomy as t2 ON r2.term_taxonomy_id = t2.term_taxonomy_id
			LEFT JOIN wp_terms as terms2 ON t2.term_id = terms2.term_id
		WHERE
			t1.taxonomy = 'category' AND p1.post_status = 'publish' AND terms1.term_id IN (".$args['categories'].") AND
			t2.taxonomy = 'post_tag' AND p2.post_status = 'publish'
			AND p1.ID = p2.ID
		ORDER by tag_name
	");
	$count = 0;
	foreach ($tags as $tag) {
		$tags[$count]->tag_link = get_tag_link($tag->tag_id);
		$count++;
	}
	return $tags;
}

Once you have pasted the function, you can use it in your theme:

$args = array('categories' => '12,13,14');
$tags = get_category_tags($args);

» Source: http://www.wprecipes.com/wordpress-trick-function-to-get-tags-related-to-category


WordPress tip: Get all custom fields from a page or a post

Do you ever wanted to be able to get all custom fields from a specific post or page? If yes, let’s start by pasting the following code in your functions.php file:

function all_my_customs($id = 0){
    //if we want to run this function on a page of our choosing them the next section is skipped.
    //if not it grabs the ID of the current page and uses it from now on.
    if ($id == 0) :
        global $wp_query;
        $content_array = $wp_query-&gt;get_queried_object();
        $id = $content_array-&gt;ID;
    endif;   

    //knocks the first 3 elements off the array as they are WP entries and i dont want them.
    $first_array = array_slice(get_post_custom_keys($id), 3);

    //first loop puts everything into an array, but its badly composed
    foreach ($first_array as $key =&gt; $value) :
           $second_array[$value] =  get_post_meta($id, $value, FALSE);

            //so the second loop puts the data into a associative array
            foreach($second_array as $second_key =&gt; $second_value) :
                       $result[$second_key] = $second_value[0];
            endforeach;
     endforeach;

    //and returns the array.
    return $result;
}

Once done, you can use the function like this:

$result = all_my_customs();
echo $result['my_meta_key'];

» Source: http://www.wprecipes.com/wordpress-tip-get-all-custom-fields-from-a-page-or-a-post


Check if a plugin is active

If you want to check if a WordPress plugin is active, just use the is_plugin_active() function. The function takes a single parameter, which is the path to the plugin, as shown in the example below:

<?php
if (is_plugin_active('plugin-directory/plugin-file.php')) {
    //plugin is activated
}
?>

» Source: http://www.wprecipes.com/check-if-a-wordpress-plugin-is-active-the-easy-way


Create an Anti-IE6 plugin

With this amazing code created by Nathan Rice, you’ll be able to serve IE6 users the default WordPress theme. After all, those idiots don’t deserve anything better :D
Just paste the following in a new file and save it as ie6.php. Upload it to your wp-content/plugins directory and activate it on your WordPress dashboard.
By the way, if you hate IE6 just like I do, you should definitely check out this very funny article.

<?php
/*
Plugin Name: Serve Default to IE6
Plugin URI: http://www.nathanrice.net/blog/serve-ie6-visitors-the-default-wordpress-theme
Description: This plugin will serve the default theme to any visitors using IE6.
Author: Nathan Rice
Author URI: http://www.nathanrice.net/
Version: 1.0
*/

add_filter('template', 'serve_default_to_iesix');
add_filter('option_template', 'serve_default_to_iesix');
add_filter('option_stylesheet', 'serve_default_to_iesix');
function serve_default_to_iesix($theme) {
	if(strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 6') !== false)
		$theme = 'default';

	return $theme;
}
?>

» Source: http://www.nathanrice.net/blog/serve-ie6-visitors-the-default-wordpress-theme/

Have you checked out the highly recommended Digging into WordPress book by Chris Coyier and Jeff Starr?

Top 10 WordPress Hacks from October 2009

10+ astonishing jQuery resources to spice up your website

Show/Hide a nice login panel

If your website allow user registration, it should definitely a good idea to implement this very nice sliding login form. Of course, it can be used for many other things, as such as a contact form.

» View tutorial

Easy Display Switch with CSS and jQuery

Some people prefers to read a list of blog exerpts in lines, so other prefers a column display. With this tutorial you’ll learn how to create a jQuery display switch so your readers will be able to choose their favorite display.

» View tutorial

Create a better jQuery stylesheet switcher

The purpose of this tutorial is to learn how to create a jQuery CSS switcher and let your visitor decide in what color scheme your site should be.

» View tutorial

Turn any webform into a powerful wizard with jQuery

Most of the time, Web forms are long and boring. So, what about turning them into wizards? Don’t forget to check out our list of jQuery tutorials to work with HTML forms.

» View tutorial

Chat with jQuery and PHP

I remember the time that you had to create a Java Applet to have an efficient chat application. Now, thanks to PHP and of course jQuery, you can forget heavy and boring applets.

» View tutorial

Beautiful tag clouds with jQuery and flir

Tag clouds used to be used intensively on lots of blogs two or three years ago. But nowadays, most blogs don’t use them anymore. If you also don’t use tag clouds on your blog, maybe this tutorial will change your mind?

» View tutorial

Fading colors with jQuery

If you’re looking for an interesting visual effect to put on your links, this one should be a good option. On their recent homepage redesign, Twitter used a similar effect on their homepage.

» View tutorial

Twitter-like login panel using jQuery

Talking about Twitter and their recent site redesign, I might say I really like the login panel they added. With this excellent tutorial, you’ll learn how to do the same for your website or blog.

» View tutorial

Disappearing “Scroll to top” link with jQuery and CSS

After you scrolled down a page, “Scroll to top” links are welcome. This tutorial will show you how to create a dynamic “Scroll To Top” link that will appear automatically when the page has been scrolled down.

» View tutorial

Using jQuery to recreate the product slider from Apple’s website

Ah, Apple website. Since their latest redesign, this site is often quoted by many blogs as being a must-see in terms of design and usuability. With this tutorial, you’ll be able to reproduce Apple products slider, using jQuery.

» View tutorial

Create an astonishing image rotator with jQuery

On many portfolios websites, javascripts sliders on homepage are now very common, this is why I hesitated to feature that one. But seriously, it may be common, it looks so great!

» View tutorial

Have you checked out the highly recommended Digging into WordPress book by Chris Coyier and Jeff Starr?

10+ astonishing jQuery resources to spice up your website

10 wonderful fonts you can embed with Cufon and Sifr

Scripts like sIFR, Flir, and of course Cufon made it easy for developers and designers to be able to use nice fonts as such as Myriad Pro or Helvetica Neue and since some month, we see more and more blogs or website with fancy titles.

This is clearly a great thing, because web safe fonts are extremely limitating. Though, there is a problem that many people seems to neglect: Lots of fonts licences – even free ones – doesn’t allow you to embed it on webpages, or redistribute it.

In this article, you’ll find a showcase of ten absolutely beautiful fonts that you can embed fith @font-face, Cufon, sIFR, or Flir.

Fertigo


» Get it

Delicious


» Get it

Tallys


» Get it

Museo Sans


» Get it

CA BND Bold WEB


» Get it

League Gothic


» Get it

Chunk


» Get it

Flaminia Type System


» Get it

Junction


» Get it

Andika


» Get it

Have you checked out the highly recommended Digging into WordPress book by Chris Coyier and Jeff Starr?

10 wonderful fonts you can embed with Cufon and Sifr

10+ WordPress plugins for developers

Preserve Code Formatting


Have you ever tried to display code snippets in WordPress? If your answer was "yes", I'm pretty sure you had trouble to do so, at least during your first tries. Why? Because of html entities and WordPress formatting.
By using the "Preserve Code Formating" WordPress plugin, you can say a definitive goodbye to all that kind of problems.
A definitive life saver for developer's blogs.
» Source : http://wordpress.org/extend/plugins/preserve-code-formatting/

Wp Advanced Code Editor


WP Advanced Code Editor integrates the EasyArea advanced code editor into WordPress. This adds real time syntax highlighting, line numbering, full screen editing, and more to the code editor in the "Add New Post" and "Add New Page" screens.
» Source : http://wordpress.org/extend/plugins/wp-advanced-code-editor/

runPHP


If you're a developer, you may sometimes find a bit frustrating the fact that WordPress do not allow you to run PHP code in the editor or in Text widgets.
The "Run PHP" plugin solves this problem. The permissions to run some PHP are handled by user roles and capabilities. Note that this plugin will also work on PHP 4 servers.
» Source : http://wordpress.org/extend/plugins/runphp/

Vim Color Improved


Highly inspired by the Drupal module of the same name, "Vimcolor" highlights your code in many different formats. VIM is a common programmers text editor for (usually) unix based systems. Out of the box VIM can color the syntax of 200+ languages including PHP, Perl, C, HTML, Fortran, Haskell, Java, etc.
» Source : http://wordpress.org/extend/plugins/vim-color-improved/

SQL Executionner


While working with a database-driven website, as such as WordPress, you may often need to directly look inside the database for some info, or execute a few queries to update or delete entries.
Sure, PhpMyAdmin do that job perfectly, but why connecting to another software when you can do it inside WordPress, suing the SQL Executionner plugin?
» Source : http://justinsomnia.org/2008/02/the-wordpress-sql-executioner/

Google Syntax Highlighter


The Google Syntax Highlighter plugin easily integrate Alex Gorbatchev's Syntax Highlighting code into your WordPress blog. Just install the plugin and you'll be able to automatically color the code snippets you posted on your blog.
The Google Syntax Highlighter plugin is 100% Javascript based, so it will not contribute to your server load.
» Source : http://wordpress.org/extend/plugins/google-syntax-highlighter/

Wp Development Utilities


Once you have installed this plugin, you'll be able to use a full set of functions designed to help your find and debug your WordPress themes or plugins. Among other things, you can retrieve user capabilities, web server name, get the ID of a permalink...
» Source : http://www.blogdev.info/bd/wordpress/plugins/wp-development-utilities.htm

WP Developer Assistant


WP Developer Assistant is a complete toolkit for all WordPress developers. It allows you to see all WordPress predefined constants, easy access and modify the options table, view actions and hooks, and a lot more.
» Source : http://wordpress.org/extend/plugins/wp-developer-assistant

Anti Internet Explorer 6


You probably already know that I hate IE6. This is the reason why I can't resist to list this plugin on here. It purpose is pretty simple: Once installed, it will detect the loser's browser and will deny it access to your blog.
» Source : http://wordpress.org/extend/plugins/anti-internet-explorer-6/

Hosting monitor


A website can't be great with a good and reliable host. In order to alays keep an eye on your server, you should definitely install the "Hosting Monitor", a monitoring WordPress plugin created by WebHostingSearch.
Lots of info can be retrieved and displayed: Memory usage, server load, uptime...
» Source : http://wordpress.org/extend/plugins/wordpress-phpsysinfo-widget/

Wp-Debug


Ever wished to be able to display information about GET/POST requests, session variables, server info from the php.ini, or included files? The Wp-Debug plugin allow you to see what's going on the inside.
A very good tool to learn more about WordPress.
» Source : http://wordpress.org/extend/plugins/wp-debug/

WordPress Console


The WordPress Console is definitely the kind of plugin any WordPress developer should have installed. It provide an interactive console that loads the WordPress environement.
You can then test any PHP code. A great way to learn the WordPress API! Note that a screencast and a detailed tutorial are availables.
» Source : http://wordpress.org/extend/plugins/wordpress-console/

Even more WordPress developement resources

  • WpRecipes is another blog of mine, where I enjoy sharing lots of WordPress hacks with my readers.
  • WordPress Help Sheet : Created by WpCandy.com, this help sheet will always be there to remind you about template files, functions and useful code snippets.
  • WordPress TextMate Bundle is an extension or the popular TextMate editor. A must have for all WordPress developers!
  • Nettut's WordPress Cheat Sheet is another compilation of useful resources as such as the loop, theme structure or template tags.
  • WordPress Codex is the most well known resource for all WordPress developers. You'll find pretty much anything there.

Get 20% off on the MyHomePro Premium WordPress Theme by using this exclusive code: wpcats20.

10+ WordPress plugins for developers

Cats Who Code contest: Win XHTML/CSS templates!

Introducing TemplateWire

TemplateWire is one of the numerous websites to sell XHTML/css templates. What made them different from the rest? Simply, TemplateWire aren't selling templates one by one : Instead, they ask you to pay a $29 fee which allow you to dowmload and use all the templates you want.

Let's have a look to some of TemplateWire templates:

Fashion


» Preview/Buy

Event Planner


» Preview/Buy

Media Provider


» Preview/Buy

Pets Hospital


» Preview/Buy

Apart from XHTML/CSS templates, TemplateWire are also selling logo templates as well as Flash sites templates.

The contest

If you'd like to win one of TemplateWire XHTML/CSS template, we have some good news for you: 3 of our readers will be randomly choosen on October 9, 2009 and will win the template of their choice from TemplateWire.

How to participate?

Entering our new contest is easy. Just follow the simple rules below:

  • Write a post on your blog about Cats Who Code OR tweet about us.
  • Leave a link to your post/tweet in the comments so we can know about it.
  • Get our RSS feed and follow us on Twitter : The 3 winners will be announced there on October 9, 2009.
  • Winners will have to choose the template they want on the TemplateWire site.

Good luck to everyone!

Get 20% off on the MyHomePro Premium WordPress Theme by using this exclusive code: wpcats20.

Cats Who Code contest: Win XHTML/CSS templates!

Page 5 of 2512345678910...Last »