(You’re reading Part 2 of ComicPress: The Technical Guide. Read Part 1 here.)
Site Performance
Having a responsive site means more readers can read more pages in less time. It also means that more ads will be shown, more product pages will be shown, and more search engines can index your content more often. It also means that if you get hammered by a social networking site that you can take the hits and serve all those potentially new readers. “Death by Popularity” has claimed a lot of Webcomic authors.
A Simple Way to Improve Performance
Install and activate wp-cache2. If your site’s content doesn’t change too often, set the timeout in seconds to a high value (3600 seconds = 1 hour, so if your site only changes once every day, set the timeout to 3600*24 = 86400 seconds. If you do tricky server-side dynamic stuff on your site, setting the cache time to a small value, say 120 seconds, will still provide some benefits. While you’re working on your site, be sure to disable caching, otherwise you’ll always see cached pages and you’ll never see your changes.
Things You Shouldn’t Do In Your Theme’s PHP Code When Using wp-cache2
- Changing the content based on the browser that’s visiting
- Showing things on the page that must be random
Use JavaScript for those purposes.
The Alternative PHP Cache (APC)
If you’re on a personal, colocated, or virtual private server, such as a Linode (disclaimer: affiliate link, but they are really good and I’d recommend them even w/o the affiliate program), you can most likely use APC. APC will cache compiled PHP code (called “opcode”) in memory, and this speeds up code execution greatly, as you no longer have to:
- load the code off disk
- translate it into machine code instructions
- and then throw away the code and start fresh
with each hit to your Website.
WordPress + a bunch of plugins takes up about 10 MB of memory, so be sure to allocate enough RAM to APC to avoid cache full errors. Virtual Private Servers are almost always memory-bound, so good RAM management is important. Also, too many cache full errors and your site can go down. Not good. Active monitoring of your RAM for the first few weeks of using APC, until you understand how your site reacts with it turned on, is crucial.
If you’re really good at PHP, you can even cache the slower parts of your theme in APC’s shared memory and get an incredible speed boost. The sidebar on my site performs a lot of database accesses. It’s also the same across all pages on the site at all times. Even with wp-cache2, that sidebar will need to be redrawn with every page access, so creating the sidebar once and caching it in memory improves site performance even more than with just wp-cache2 alone.
There are other opcode caches out there, but I like APC because it is easily installed as a PECL module. It’s also free.
Installing and Choosing a ComicPress Default Theme
Download and unzip the ComicPress theme distribution, then upload all of the folders to the wp-content/themes/ folder in your WordPress install. Within the ComicPress installation are a number of default themes, geared toward different comic sizes/orientations. You can then use the theme selector to swap between themes and see which one you want to start your customization with.
Configuring ComicPress
Two parts of your site need to be configured properly for ComicPress to work:
- there need to be enough categories defined
- there needs to be a folder created to hold your comics.
Both of these parameters are defined in the comicpress-config.php file that lives in your chosen ComicPress theme directory. Inside of comicpress-config.php, the following global variables arae defined:
- $comiccat – the ID number of the category for comic entries
- $blogcat – the ID number of the category for blog entries
- $comic_folder – the name of the folder that holds your comic image files
- $rss_comic_folder – the name of the folder that holds your RSS feed image files
- $archive_comic_folder – the name of the folder that holds your Archive page image files
- $archive_comic_width – the width, in pixels, of the images in the Archive folder
- $blog_postcount – the number of blog category entries to appear on the home page of your site
You can edit this file by hand, or you can use ComicPress Manager to edit your config. Additionally, if you have ComicPress Manager installed, you’ll be warned if you’re missing any of these critical components.
Comic Folder
By default, ComicPress expects a directory called comics to be located in the same place as the WordPress index.php file (this may be different if you’ve moved your WordPress root):
- /index.php
- /wp-content/
- /comics/
Your comic files are placed in this directory. This directory name can be changed in the comicpress-config.php file. Enter in the name of the folder, without leading or trailing slashes, in between single or double quotes, as the value for the $comic_folder variable:
$comic_folder = "my_comic_folder";
The archive and RSS folders have the same format (more about them below):
$archive_comic_folder = "my_archive_comic_folder";
$rss_comic_folder = "my_rss_comic_folder";
Categories
A ComicPress install requires that two categories be defined in WordPress, a comic category and a blog category. Child categories are not supported at this time. In the WP Admin area, visit Manage -> Categories and make sure you have at least two categories defined.
If you are manually editing your comicpress-config.php file, you will need the category ids. The easiest way to obtain these is to visit Manage -> Categories, enable the status bar in your browser, and then hover over the link to edit the category. The category will appear in the url in the status bar, as a number, after the cat= part of the url.
This category id is then placed, in double quotes, into the appropriate variable definition in the comicpress-config.php file for your theme, either for $blogcat or for $comiccat:
$blogcat = "3";
$comiccat = "5";
Other ComicPress Settings
Two additional settings in comicpress-config.php are the Archive image width and the homepage blog post count. The Archive image width ($archive_image_width) is used to scale comic images for Archive views, and is also used by ComicPress Manager as the size at which to generate thumbnail images. The homepage blog post count ($blog_postcount) controls how many posts that are in your $blogcat will be shown on the home page. If you don’t want a blog on your homepage, for instance, set this to “0″.
Naming Comic Files
By default, comic files are named with a prefix of YYYY-MM-DD and require an extension (gif, jpg, png). Everything between the end of the date and the period that separates the extension is optional with regards to ComicPress. ComicPress Manager uses that information between the prefix and extension to automatically generate a title for the posts that it generates. The date format can be changed by modifying the calls to mysql2date() to use a format other than Y-m-d.
Using the default format, dates need to be zero-padded. So, for a comic that goes live on January 1, 2008, the date would be 2008-01-01.jpg.
Changing the Date Format
If you want to use a different date format, such as YYYYMMDD (which translates to mysql2date(’Ymd’)), you have three options, all of which require modifying the functions.php file in your chosen theme:
- Find-and-replace all occurrences of Y-m-d with your chosen date format. The date format for mysql2date() is the same as the PHP date() function’s format.
- Define a constant at the top of the file with your chosen date format, then find-and-replace all occurrences of Y-m-d with the name of your constant:
define("CP_DATE_FORMAT", "Ymd");
...
$todays_comic = mysql2date(CP_DATE_FORMAT, $post->post_date);
- If you’re using ComicPress Manager, you’ll need to configure the default date format there anyway. Use ComicPress’s defined constant, CPM_DATE_FORMAT, in your theme:
$todays_comic = mysql2date(CPM_DATE_FORMAT, $post->post_date);
Creating a Comic Post
For this example, we’re assuming a comic that is going live on January 1, 2008. Upload a comic to the comics folder with the correct date prefix:
/comics/2008-01-01-my_new_years_comic.jpg
Log in to WordPress and write a new post. Set the go-live date of the post to be the same as the date of the comic (2008-01-01). The time of the post matters somewhat in that WordPress is not yet Daylight Saving Time aware. Theoretically, publishing a post at 12:00am in DST means the post goes “live” one hour earlier on the prior day. I publish my own comics after 2:00 am for this reason. There are plugins which compensate for this deficiency, but I’ve never tried any of them:
Be sure to select the comic category you defined earlier to be the category for the post. Publish the post and you’re done! Webcomics Fame!
Archive & RSS images
By default, ComicPress will take the files as they exist in the comics directory and scale them, via HTML (<img width=”<?= $archive_image_width ?>”>), for the Archive view, and will deliver the unscaled images in the RSS view. You have a couple of options when it comes to setting up your Archive and RSS views:
- Use this default setup, which is the simplest but most inefficient – you will be delivering very large files and then scaling them down to smaller sizes. The scaling for all but the most modern browsers is also not the most ideal, and the scaled images will look blocky.
- Deliver full comics for the RSS feed, and deliver thumbnail comics for the Archive. You will need a separate comic_archive folder, and each thumbnail needs to be named exactly the same as the larger version of the comic.
- Deliver the same reduced comic file for both the RSS feed and the Archive. Set both the archive and RSS comic folder to the same value, creating the thumbnails as above.
- Deliver a separate RSS image and a separate Archive image. Define two folders, one for RSS and one for archive, and put your thumbnail images (again, named exactly the same as the larger version of the comic) in the appropriate folders.
Right now, ComicPress Manager can automatically generate thumbnails for the Archive and RSS folders, but they will both be at the Archive size. Being able to generate thumbnails for the RSS feed will be added in a future version of ComicPress Manager.
ComicPress Manager
OK, so I’ve already mentioned it a dozen times, and it has its own button on in the sidebar, but what is ComicPress Manager? ComicPress Manager is a WordPress plugin which simplifies ComicPress site management. It creates a new tab on the WordPress admin screen. It is recommended that you make sure you understand how ComicPress functions by uploading and posting a few comics manually at first. After you understand how ComicPress Manager works, use it to save you a lot of time in managing your comic.
Permissions (for Unix-based hosts)
In order for ComicPress Manager to be able to write uploaded files, thumbnails, and config file changes to your Webserver, you’ll need to correctly set the permissions on the comics & theme folders. The correct permissions vary depending on the setup of your host:
- Your web site is delivered by a webserver that runs as your username. Any files written by the webserver have the same permissions and needs that you would have. You shouldn’t have to change anything. This setup is rare.
- The webserver runs as a special user, and both you and it belong to the same usergroup. The directories and files need to be made group writable. In Unix parlance, this means chmod 775 for directories and chmod 664 for files.
- You and the webserver share no permissions. This means that the directories and files need to be made world writable, and that special care needs to be taken to ensure that the only script that writes to these folders & files is ComicPress manager. In Unix parlance, this means chmod 777 for directories and chmod 666 for files.
If for some reason you are unable or unwilling to set up the permissions on your comic & theme folders in any of these ways, you won’t be able to use ComicPress Manager. Go ahead and skip to the next part of this guide.
The following directories need to have their permissions set so that ComicPress Manager can write to them:
- Your ComicPress theme folder in wp-content/themes/
- The comicpress-config.php file in your theme directory
- Your comic folder and your RSS & archive folders, if you are using those
- All of the comic files within your comic, CSS, & archive folders
ComicPress Manager will generate warnings and/or errors when the directories won’t allow writing by the webserver process.
PHP Safe Mode
Safe Mode is an option used to attempt to secure PHP scripts on shared hosting setups. It can cause a number of issues with regards to including files, reading directories, and permissions. Getting ComicPress Manager to work in Safe Mode can take some work, as it needs to be able to read a directory outside of the directory the script lives in. This is beyond the scope of this guide. Safe Mode is being removed in PHP 6, as it’s not PHP’s job to enforce security in shared hosting setups.
Permissions (for Windows-based hosts)
Most Windows Webservers will be using NTFS file systems on their hosting drives. By default, ComicPress Manger will upload all files to Windows with chmod 777, which translates into inheriting the permissions of the parent folder and ensuring that the read-only property is not set. You’ll need to make sure the destination folders have enough permissions for the IIS/Apache user so that they can write to the folders.
Windows & Temp folders
Be sure that only one Temp folder is defined in your php.ini file, and that it is writable by IIS, otherwise you will have errors that are tough to track down. The indicator that you have a problem with Temp folders is that, when you upload a comic, it will have no permissions when moved to the WordPress folder, and can only be removed by a user with Administrator privileges.
ImageMagick and GD
Image processing for making thumbnails is done using either the ImageMagick convert tool or the GD image processing library, with ImageMagick being preferred as it supports better scaling modes. If no image processing tools are found, you won’t be able to automatically generate thumbnails and you’ll receive notifications to this effect. ImageMagick integration only works so far on Unix, as ComicPress Manager uses shell_exec(’which convert’) to find the convert binary, and I don’t know what the best approach would be for Windows to find convert.exe.
Uploading Comics and Generating Thumbnails
ComicPress Manager will handle generating posts and, if properly configured, thumbnails for all file uploads, regardless if you’re uploading individual images, multiple images, or images packed in a Zip file (this operation requires the Zip extension). When creating posts, ComicPress Manager will use the text after the date prefix to generate the title of the post. For example, the title for the comic file 2008-01-01-my_new_years_comic.jpg will be My New Years Comic. This automatic conversion can be overridden, and a large number of other post settings, including default post bodies, default tags, and post time, can be set in the upload interface. Thumbnails for RSS and archive images can also be uploaded, and you can also replace existing files on the server with another file of your choosing, renaming the source file to the target filename in the process.
You can also generate thumbnails for any existing comic image on your server, and you can delete comics and their associated posts and thumbnails.
Importing Files from another Webcomic System
Provided that your files are named with the ComicPress date prefix, you can create posts for files that have already bee uploaded to your comics folder. The post creation options are the same as for file uploads.
Editing the comicpress-config.php file from ComicPress Manager
The configuration for your ComicPress site can be managed in ComicPress Manager. Backups of your config will be written to your theme directory just in case something goes wrong, and you’ll be able to restore from a prior backup in case of problems.
By configuring through ComicPress Manager, you’ll ensure that the correct values for categories and directories are selected, which helps to eliminate common errors.
And that’s Part 2! Stay tuned for the final part, which will cover Theme Editing and Support Options for ComicPress & ComicPress Manager.