News - Podcast Interview and a New Focus for the Blog

Sarah
Chapter 3 Page 22

ComicPress: The Technical Guide (Part 3 of 3)

(You’re reading Part 3 of ComicPress: The Technical Guide. Read Part 1 here and Part 2 here.)

Editing your Theme

It’s always best to edit a copy of your existing theme and use a plugin like Theme Tester or the built-in WP 2.6 theme testing functionality so that you’re not editing your live site. If you break your live site, not only can you drive away visitors, but you can reveal information about your server that attackers can use to take down your site.

ComicPress themes the following types of WordPress pages with the following files:

  • The index page (index.php)
  • A single blog post (single.php)
  • A page (page.php)
  • An archive results page (archives.php)
  • A search results page (search.php)
  • The page that’s shown when a bad page/category is requested (404.php)
  • The sidebar (siedebar.php and/or sidebar-left.php & sidebar-right.php)

For each of these pages, the following additional php pages are loaded:

  • functions.php (loaded before the rest of the theme is loaded)
  • header.php (loaded when get_header() is called on the theme page)
  • footer.php (loaded when get_footer() is called on the theme page)

And finally, with ComicPress, comicpress-config.php is loaded from functions.php. All of these files are loaded after any plugins are loaded, so that themes will have access to plugin functions.

The Loop and The Sidebar

WordPress templates revolve around a concept called “The Loop” - a block of code that is repeated once for every post that is found in a database query. When a page is loaded, WordPress will figure out what database query to perform and will create a global query object, $wp_query, to represent the query. This object is then used by the functions have_posts() and the_post() to pull individual posts out of the query, in the order specified by the query, so that your theme can act upon them. The other template functions also use $wp_query along with $post, $wpdb, and a number of other global variables.

The problem with this approach is shown when you want to make additional queries beyond the main query, which you often do in the Sidebar. Those global variables can get wacked very easily, and this will make your paage behave incorrectly. Additionally, there are certain templating functions that only work if WordPress believes that you are in the “main” loop, or that you are out of it. To be able to do the things that ComicPress needs to do, it has to:

  • Preserve the main loop query global variable before making any other database queries
  • For certain operations, either force WordPress to believe that you are in the main loop, or that you are out of the loop, or that you are on a certain type of page in the site

This is well out of the scope of this introductory document, and requires some PHP knowledge to get working correctly. Even then, it’s still quite frustrating to deal with, if you want to stay within the accepted WordPress API.

Bandwidth

Mobile phones, dial-up users, and satellite internet providers (and even users on mad fast broadband connections) will appreciate a quick download of your site. Besides reducing image sizes, which is well-documented throughout the internets, there are a number of techniques you can use to reduce bandwidth usage.

Wp-compress-html

This plugin will remove whitespace from your source files. If you’re using firebug to debug your sites, you won’t need to look at the source file much anyway. Combined with wp-cache or a fast server with APC, this can efficiently reduce the bandwith of your pages by a significant amount. Be careful, as you’ll need to exclude certain parts of your site from processing, specifically JavaScript parts of your site. Improperly configured, it can strip out things such as Project Wonderful ads (which us Webcomic authors all love to use) and analytics tracking systems like Piwik and make them non-functional.

Trimming plugin fat

Plugins can load all sorts of other files which may be unnecessary. Firebug’s network tool will help you find extra files that are being loaded.  I like Event Calendar a lot, but if you’re not using its built-in display functionality, or you want to use your own styles, you can safely remove the wp_head hook from the evencalendar3.php file. This is a much more sophisticated procedure, so you’d better know what you’re doing. Also, this procedure is different for all plugins, so be careful!

(As a note, you really should be using Firebug to do your initial page designs & debugging, and then test in other browsers. IE 8 beta 2 and Google Chrome provide similar tools, but they aren’t as fully featured as Firebug. Yet.)

Trimming CSS fat

Dust-me Selectors can help you identify CSS selectors that are defined but are not in use. Each unused selector can take up anywhere from a few bytes to several kilobytes of file size and memory, and their existence only complicates the CSS file. Backup you style.css file first!

Xdebug (for VPS or colocated hosts)

If you can, install Xdebug. This PHP extension gives you many powerful debugging tools, the three most
important being:

  • Backtraces for all PHP errors & extensions, helping you quickly pinpoint where your code failed and how you got there
  • Improved var_dump() output for even better variable analysis
  • Code profiling support to help you find bottlenecks in your code

Proper use of Xdebug for profiling your WordPress theme is well beyond the scope of this introductory document.

The ComicPress Support Forum

If you haven’t already taken advantage of the ComicPress Support Forum, then be sure to stop by and create an account. If you have a problem or are able to help out with another user’s problem, we’d love to hear from you!

Show Debug Info

For simple problems related to theme issues, image folder permissions, and basic PHP configuration, Show Debug Info will provide enough information to help debug your problems.  Debug Info should always be Private Messaged to johncoswell (my username, duh), as it can contain information that could expose your server to attacks or foul play.

Error Messages

If your server is configured to display PHP error messages on screen, and there is a fatal error in the script, copying and pasting the error into a Private Message to johncoswell will help him debug the problem. For your protection, do NOT post error messages straight on the forum.

Server Error Logs

If your server is not configured to display PHP errors, or if the error is more complex than a single PHP error or Debug Info run can describe, you may be asked to provide error logs from your server. Ever configuration is different, and your Webhost can assist you with getting access to your error logs. These would be emailed to John for closer inspection, as they can reveal a LOT about your server, including problems unrelated to ComicPress & ComicPress Manager. PRETTY PLEASE DO NOT POST ERROR LOG INFORMATION STRAIGHT ON THE FORUM.

And that’s it! As usual, any comments or questions should be posted in the, um, comments section below. More Webcomics tech goodness in a few weeks!

Read more news...

Close
E-mail It