New book on WordPress Theme Development: WordPress Themes In Depth

Compressed JavaScript Compression

In this article, we extrapolate our favorite CSS-compression technique for JavaScript. Below, we outline the steps required to auto-compress your JavaScript documents via gzip and PHP. Two different compression methods are presented. The first method does not require htaccess, but rather involves the manual editing of JavaScript files. The second method employs htaccess to do all the work for you, thus requiring much less effort to implement. In either case, the result is the same: automatically compressed content delivered only to supportive browsers, resulting in reduced bandwidth, faster loading times, and smiling visitors :) Read more »

Fast, Effective PHP Compression

PHP compression is an excellent method of conserving bandwidth and reducing client download times. We have already discussed an excellent method for CSS compression, and in this article we share a super-easy technique for compressing all PHP content without editing a single file. Using two PHP files and two corresponding lines of .htaccess, it is possible to compress your PHP files via gzip-encoding. Browsers and other user-agents capable of interpreting gz-encoded data will employ the compressed content, while other user-agents will utilize the content uncompressed. Read more »

Go Back via JavaScript and PHP

Use this simple code as a button that will return users to the previous page: <form> <input type=”button” value=”Return to previous page” onClick=”javascript:history.go(-1)” /> </form> Here it is as a simple text link: <p> <a href=”javascript:history.go(-1)” title=”Return to the previous page”>&laquo; Go back</a> </p> You can make things easier by serving PHP and printing the link automatically. Here is the button link: echo “<form><input type=\”button\” value=\”Return to previous page\” onClick=\”javascript:history.go(-1)\”></form>”; And here is the PHP code to print a "Go back" text link: echo “<p><a href=\”javascript:history.go(-1)\” title=\”Return to previous page\”>&laquo; Go back</a></p>”; Better yet, you can kick the accessibility factor […] Read more »

Automatic Language Translation Methods

As you may have noticed, Perishable Press recently added automatic language translation to each of our articles. The free, automatic translations are available as a series of image links (via corresponding country flag icons) next to each article’s individual post view. We have found that providing this free service is important as many of our visitors come from countries other than the United States, and therefore may be unable to read our articles as presented in the English language. Although there are several excellent translation services currently available, our research has determined that Google’s free translation service exceeds our expectations […] Read more »

Time Test

This post exists entirely for the sake of tweaking time functionality in Apache, PHP, SQL, and WordPress.. Immediate findings: Date/time limit into the past for WordPress: December 13, 1901 @ 15:45 WordPress will display December 13, 1901 @ 15:45 properly for all functions except wp_get_archives All dates prior to 12/13/1901 in MySQL will display as December 31, 1969 @ 19:00 in the WP Admin > Post Timestamp panel SQL timestamps of 0000-00-00 00:00:00 display as 0 via $wpdb->get_col(“SELECT DISTINCT YEAR SQL timestamps of 0000-00-00 00:00:00 display link as the current year when permalinks are enabled An SQL timestamp of 1000-00-00 […] Read more »

Perishable Press Triple Loop for WordPress

Two of the themes developed by Perishable Press, Apathy and Information, depend on three WordPress loops to operate as intended. For each of these themes, the three loops consist of two "side" loops and one main loop. The side loops each display posts from one specific category, while the main loop displays posts from every category not specified in the side loops. There are many different multi-loop configurations currently available for WordPress users. Needless to say, despite a wide variety of available loop setups, implementing a customized multiple loop frequently requires a great deal of time of energy. Certain loop […] Read more »

Customize WordPress Quicktags

Note: This condensed tutorial assumes you are working with WordPress 2+ and are familiar with editing .php and/or .js files. WordPress quicktags1 provide shortcuts for adding certain bits of code to your posts. The default set of quicktags includes some handy shortcut buttons for tags such as <strong>, <a>, and <img>, as well as a few others. While the default set of quicktag buttons is occasionally useful, a quick bit of quicktag customization can easily transform your personal set of quicktag buttons into a deadly arsenal of time-saving code shortcuts. First, open the quicktags.js file, usually located in the wp-includes/js […] Read more »

Auto Clear and Restore Form Elements

Using a small bit of JavaScript, it is possible to auto-clear and restore form elements when users bring focus to them. Simply copy, paste, and modify the following code example to achieve an effect similar to this: Here is the HTML/JavaScript for your website: <input value=”Click here and this will disappear..” onfocus=”if(this.value == ‘Click here and this will disappear..’) {this.value = ”;}” onblur=”if (this.value == ”) {this.value = ‘Click here and this will disappear..';}” type=”text” size=”77″ /> Update [January 2nd, 2007] » Here is another auto-clear JavaScript trick that cleans up the (X)HTML code but does not auto-restore the element. […] Read more »

Display the Total Number of WordPress Posts, Comments, and Categories

Would you like to display the total number of posts, comments, and categories for your WordPress-powered website? Here is the code that can make it happen 1! Update: The count posts part of this method should only be used for WordPress versions less than 2.5. For WordPress versions 2.5 and better, there is a built-in function for displaying the total number of posts. See The WordPress Codex for more information. <?php $numposts = $wpdb->get_var(“SELECT COUNT(*) FROM $wpdb->posts WHERE post_status = ‘publish'”); if (0 < $numposts) $numposts = number_format($numposts); $numcomms = $wpdb->get_var(“SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = ‘1’”); if (0 […] Read more »

Execute External WordPress Functions

To execute WordPress functions in an external directory (i.e., outside of the WordPress install directory), it is necessary to include a call to “wp-blog-header.php” at the top of the external file. For example, if your WordPress-powered blog is located in a subdirectory called “blog” and the external file is in the domain root (e.g., the external file is located directly in http://domain.com/), add the following code to the top of the external file: <?php require_once(“./blog/wp-blog-header.php”); ?> This may be generalized by writing: <?php require($_SERVER['DOCUMENT_ROOT'].’/blog/wp-blog-header.php’); ?> Read more »

WordPress Search Function Notes

Code to call an external WordPress search form: <?php include (TEMPLATEPATH . “/searchform.php”); ?> Code for a standard, inline WordPress search form: <form id=”searchform” method=”get” action=”<?php echo $_SERVER['PHP_SELF']; ?>”> <p><input name=”s” type=”text” id=”s” size=”33″ maxlength=”99″ /> <input type=”submit” class=”submit” value=”Search &raquo;” /></p> </form> Code to search through multiple categories when using customized, individual category pages: <form id=”searchform” method=”get” action=”<?php echo $_SERVER['PHP_SELF']; ?>”> <p><input name=”s” type=”text” id=”s” size=”33″ maxlength=”99″ /> <input type=”hidden” name=”cat” value=”1,2,3,4,5,6″ /> <input type=”submit” class=”submit” value=”Search &raquo;” /></p> </form> Code to try if the search function fails and your blog is located in a directory other than root: […] Read more »

Backup that Database with phpMyAdmin

DB Export Settings Backing up your database as often as possible is essential. For WordPress, as well as for other applications, plugins and other scripts that help automate the task are easily obtainable. However, for several reasons, it is a good idea to understand the process of manually creating a backup copy of your database. This brief tutorial1 should help cement the process into a solid reference. We are assuming that you have an SQL database and have access via phpMyAdmin. Before reading through the gory details written below, check out the screenshot to the left (click on the image). […] Read more »

Passing Quotation Marks via wp_link_pages

According to the WordPress Codex 1, it is possible to pass quotation marks via the parameters of the function, wp_link_pages(). This would enable users to assign a particular css class or id to the function output, thereby providing greater design and behavioral control over that particular object. But alas, as reported several times in the WordPress Codex 2, wp_link_pages() is unable to pass quotes without causing errors. To fix this, we open template-functions-post.php and find wp_link_pages(), which is located around line #121 (for WP 2.0.2). The fix is easy, simply edit the <p> in the following lines: $r['before'] = ‘<p>’ […] Read more »

Reversing WordPress Page Navigation Order

This article explains how to reverse the order of WordPress page navigation links. To reverse the default (backward) order of page navigation in WordPress, open the file template-functions-links.php (in WP 2.0) or link-template.php (in WP 2.1/2.2) and scroll down to the last function, posts_nav_link() 1. Next, find the last if statement and switch the order of the following two lines: previous_posts_link($prelabel); [ ignore this line ] next_posts_link($nxtlabel, $max_page); Next, within the first line of the same function (beginning with function posts_nav_link), switch the order of the variables $prelabel=’&laquo; Previous Page’ and $nxtlabel=’Next Page &raquo;’. Finally, within the loop, make sure […] Read more »

Permalink Enlightenment

I recently enabled the permalinks feature for a fresh WordPress 2.0.2 upgrade. The process required several hours of research and approximately 90 minutes to fully implement. This brief article summarizes the process and applies to at least the following setup: WordPress 2.0.2 Apache Server with mod_rewrite enabled The ability to access/modify your .htaccess file(s) You have decided to use the /%year%/%monthnum%/%day%/%postname%/ permalink format (actually, any format will work; simply swap your preferred format for the one mentioned here) You may also be using any of the plugins listed in the dungeon (actually, most plugins are compatible — only a few […] Read more »

Latest Tweets Book update! New version of WordPress Themes In Depth now available: wp-tao.com/wordpress-themes-bo…