WordPress & Blogging
I now have available for download my second WordPress plugin: Deko Boko, a contact form that uses reCAPTCHA for spam protection. There are a number of good contact forms for WordPress, so why create another one? There are two things that make Deko Boko different from the others:
- It uses reCAPTCHA for blocking spam. reCAPTCHA is a great project that uses data from its captcha form submissions to help digitize books.
- The Deko Boko contact form can be extended any way you want, but without the need for complicated admin menus. If you’re comfortable editing HTML, then you can add any number and any type of input fields to the contact form. You can control which fields are optional or required. When the form is submitted, any fields that you added will have their data included in the body of the email.
The form layout is controlled by a CSS styled definition list, which provides a great deal of flexibility. With just a few CSS edits you can change the position of the field labels to top-aligned, left-justified, or right-justified.
Spam protection in addition to reCAPTCHA is also included. Deko Boko protects against email header injections and will verify that the return address provided by the user has a valid format.
This is a beta release (v0.8). I’ve been using it on my own site for some time and it’s working well. I’d like to hear feedback before making it an “official” release.
Go to the Deko Boko page for more information and to download it. Note that comments are turned off on the page - please submit any comments on this post.
If you click around into different parts of my site, you’ll notice that only certain categories of posts appear on the home page, and there are two variations to my sidebar. What I’ve done is make a single blog look like two different blogs: one for my professional work, and one for my personal posts. I’ve achieved these effects without using plugins, and without registering multiple sidebars. The only downside to my approach is that it’s not a technique you can use to control which widgets appear on which pages (but it’s fine if you want your widgets on all your pages). I don’t use widgets so it’s not a downside for me
.
To follow along, you’ll need to be comfortable with editing a couple of your theme’s files, and be comfortable with the basics of PHP.
Limiting the categories on your home page can be done by adding a few lines of code to the top of your theme’s index.php file.
<?php if (is_home()) {
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts("cat=12,23,6&paged=$paged");
} ?>
For “cat=” on the 3rd line, list the numbers for the categories you want to appear on your home page (or you can put a minus sign in front of the category numbers to exclude specific categories). The WordPress documentation for query_posts says you can do this with simpler syntax, but you can’t. The documentation is wrong. If you follow the suggestion there, your “Newer Entries” and “Older Entries” links on your home page won’t work. They will just continually re-load the most recent posts. The code I’ve given here is explained nicely in this WordPress support forum post.
So with this code, my home page includes only the categories related to my professional work. For my personal blog, I needed a way to get posts from all the right categories to appear together on a page. The answer is simple: I created a single parent category that encompasses all the categories I use for my personal posts. So the page for that parent category serves as the “home page” for my personal blog.
I also wanted my sidebar to change depending on whether you are viewing the “professional” pages or the “personal” pages. Achieving this involves two steps. First, add the following code to the top of your sidebar.php file. The category and page numbers you see listed are the ones where I want the “professional” sidebar to appear, which I call $home_sidebar (so you should substitute category and page numbers appropriate for your site). Note the ability to pass an array to is_category is new with WordPress 2.5.
<?php
$home_sidebar = false;
if (is_category(array(12,23,6))
|| in_category('12') || in_category('23') || in_category('6')
|| is_page(array(345,440,496,501)) || is_home()) {
$home_sidebar = true;
}
?>
The second step is to check the value of $home_sidebar whenever you want to vary what appears in the sidebar. For example, to vary the category links in your sidebar, use code similar to this (again, substituting your category numbers). You’ll want to explore the options for the wp_list_categories function to get the exact appearance you want:
<ul>
<?php if ($home_sidebar) {
wp_list_categories('include=12,23,6&feed=RSS&order=desc&title_li=');
}
else {
wp_list_categories('child_of=26&feed=RSS&title_li=');
} ?>
</ul>
Note my use of child_of. This is the number for the parent category I created for all of my personal posts. This is a very convenient way to get all of the child categories without having to list them individually.
I’ve used this approach to make my blog look like two blogs. But you could easily extend this approach to subdivide your blog into as many mini-blogs as you like.
Shashin 2.1 is now available. It does not include any new dazzling features, but it has a new, easier to use option for displaying all your album thumbnails, and then have them link to a page on your site that displays all the photos in each album. The Shashin page has instructions on how to do this.
There were 3 problems with how I implemented this feature in the previous (2.0) version of Shashin, but they only became clear to me after hearing feedback from people using Shashin 2.0 in a wide variety of WordPress themes. One problem was that the steps involved were just too complicated for most people’s needs (but the more complex options are still there, if you need greater control of the configuration than the new “easy” way).
The second problem was my attempt to manipulate the title of the page containing the [salbumphotos] tag. Shashin 2.0 tries to dynamically append the title of the selected photo album to the page title. In a rational world this would be easy, but WordPress makes it extraordinarily difficult to isolate and manipulate the title of a page, as reported here. I thought I had come up with a work around. But, as it turns out, my solution was not reliable across all the different WordPress themes that are out there. So, with Shashin 2.1, I have removed all the code that tries to manipulate the page title. It now simply displays the album title as a caption on the table that contains the photo thumbnails. This is much cleaner and shouldn’t cause conflicts with any themes.
The third problem was the [salbumphotos] tag, which is used to display thumbnails for all the photos in an album. In Shashin 2.0, a page with the [salbumphotos] tag won’t play nicely with sidebars that use the wp_list_pages function (for listing links to all the pages on a site). The [salbumphotos] tag only worked correctly if you used it in conjunction with Shashin album thumbnails. You couldn’t just go to the page directly from a sidebar link. This is fixed in Shashin 2.1.
Shashin 2.1 also has a few minor bug fixes, the most important of which is that you can now once again see the photo thumbnails in the Shashin admin panel.
I should point out that, if all you want to do with your Picasa photos in WordPress is display your album thumbnails on a page, and then link them to a page that displays the photos in each album, then I recommend kPicasa Gallery. It has similar features to Shashin in this area, but without Shashin’s management overhead. But if you want to do more than just that, then I recommend Shashin
.
I’ve redesigned toppa.com to support my web consulting work. How do you like the logo?
Other than the new look, the big change is that I’ve split my blog in two. Posts that show up on the home page concern web technology and my projects. Everything else is still on the site, but is in my personal blog. There’s also a link for it at the bottom of the sidebar.
For my RSS fanbase (yes, I’m trying to be funny…), you can get all my posts from this feed, or just the personal blog posts from this one.
Under the hood it’s still one blog. Figuring out how to get WordPress to display everything as if it were two blogs was an interesting challenge (one that has frustrated a number of people, judging by the threads in the WordPress support forums). It’s not just a question of limiting the topic categories that show up on the home page. It’s also a question of how to group the other categories together, and how to get the sidebar to show the appropriate navigation controls for the current context (i.e. listing the correct subset of categories on the home page, as well as on each different category archive page). I’ll write up a how-to post soon.
This is a very minor release in terms of code changes. It’s not critical if you have a previous version of Shashin installed, but it is critical if you’ve upgraded to Wordpress 2.5 and you’re installing Shashin for the first time. It has to do with WordPress 2.5’s new handling of variable scope when activating plugins (if you were curious).
The only other change I made was to add mp4 as a video type that Shashin will recognize (it’s not documented as a supported video type for Picasa, but it does in fact accept them).
Download Shashin 2.0.4.
Update: I’ve received a few reports from first-time Shashin users who are having trouble activating Shashin properly, despite this fix. This seems to be happening to only a small number of people, and I haven’t been able to track down the cause yet. If you are having trouble with Shashin under WordPress 2.5, please leave a comment on this post and let me know exactly what’s going wrong.
In version 2.0.2 I updated Shashin to accommodate changes in the Picasa RSS feed. The feed changes had caused images to stop displaying after you synced your albums in Shashin. I fixed that, but what I didn’t notice was that they also changed how videos are represented in the feed, so version 2.0.2 still doesn’t display videos after you sync your albums. Someone kindly pointed out the problem, so I’ve fixed it - Shashin 2.0.3 is now available at wordpress.org.
Murphy’s Law is being strictly enforced today: within 24 hours of my 2.0 release, Google coincidentally changed the Picasa RSS feed. The URL for the photos isn’t where it used to be in the feeder, with the result that, if you sync your albums in Shashin, your photos won’t show up anymore. I’ve found the new tag for the photo URLs in the Picasa feed and updated Shashin accordingly. So download Shashin 2.0.2 now. Note that your photo data is still safe in Shashin even if your photos stopped appearing after the Picasa RSS feed change. Syncing the albums with 2.0.2 should straighten everything out.
This is the one real problem with building an application that relies on Google’s RSS feeds - I have no control over when they might change the feeds, or what kind of changes they make.
There are also some other minor fixes. Here’s a list of the changes in 2.0.2:
- Adjusted for new location of the content_url in the Picasa feed
- If you select the option to display your photos at Picasa in a new browser window, it actually works now
(the formatting of the anchor tag was incorrect).
- Shashin now performs a preg_escape when detecting the URL for the page containing your salbumphotos tag. This fixes a warning that was being displayed for some URLs in PHP 5.
- Shashin now correctly detects your WordPress installation directory if you’ve installed it in a subdirectory (except for paths in shashin/display/highslide.css which are hardcoded - you’ll need to edit those by hand).
Shashin 2.0 is now available. I jumped the version number to 2.0 because this release includes a couple major new features. One is that Shashin is now bundled with Highslide. It was a fun challenge getting WordPress to play nicely with Highslide for displaying any combination of photos in a post, and then any combination of posts on a page. The other major new feature is linking album thumbnails to a local display of the album’s photos, so you can show them on your site instead of having to go to Picasa.
There are minor new features too: a new tag that lets you display sets of album thumbnails alongside their titles and descriptions, an option to prefix album titles to photo captions, and if you choose not to use Highslide, you can open the links to Picasa in a new window if you want.
All the details, including instructions for using the new features, are on my Shashin page.
If you have any questions or run into any problems, please use the comments on this post.
In my announcement of Shashin 1.2 the other day, I said I didn’t have as much time for testing as I would have liked, for the sake of getting out a version that works with WordPress 2.3.3. Sure enough, there were several bugs in Shashin 1.2. Get the fixes in version 1.2.3 from wordpress.org.
It may fix the problem some people were reporting with adding and syncing albums (a problem I haven’t been able to reproduce, so I can’t say for sure). If you had this problem, please let me know if the new version fixes it for you.
I also took the opportunity to rewrite the algorithm for displaying random photos, and it works much more nicely now, so give it a try.
I believe I may have also found why some, but not all, Shashin users were having trouble with multibyte (e.g. Chinese) characters, so this upgrade may help with that as well.
If you have any questions or problems, please post a comment on this post.
Update: There were some bugs in this version, please see my post on version 1.2.3 for the latest update. Also go there for any comments or questions - I’ve turned off further comments on this post.
You can download the latest version of Shashin from wordpress.org. I had to rush this out the door, since Shashin 1.1 doesn’t work with Wordpress 2.3.3. That means I didn’t do all the testing I usually do before a release. If you have any problems, please post a comment here (note I turned off comments on the main Shashin page, as the page was just getting way too long).
The two big new features happen to be the two most requested features: displaying groups of album thumbnails, and the ability to add or sync all your Picasa albums at once. For the album thumbnails, they are displayed in a table with a number of columns you can specify, you can choose to display either only certain albums, or all your albums with your choice of sorting preference, and you can choose whether to display the album titles and locations (if you specified a location in Picasa, Shashin will include a Google Maps link as well). Syncing all your albums at once will make using Shashin easier for those who maintain a lot of Picasa albums.
Another feature I added is smarter album syncing. Now if you move a photo from one album to another in Picasa, Shashin will preserve its original photo key when it syncs the albums. Before I made this change, the old photo key would be deleted and the picture would get a new photo key, thus breaking any Shashin tags that referred to the old key. That problem won’t happen anymore.
The biggest piece of work in this release wasn’t the new features though. It was writing a parser for the Picasa feed from scratch. I got tired of Shashin breaking every time WordPress changed its RSS tools (which seems to happen with almost every new version - that’s what broke Shashin 1.1 when WordPress 2.3.3 was released). Instead of using something big like Magpie, I instead wrote a very lean XML parser - not counting comments, the whole thing is less than 60 lines of code. It uses Snoopy to load the feed, since I can’t rely on PHP functions like fopen being configured across different servers for URL fetching (Snoopy comes with WordPress, so Shashin loads it from there). I would have loved to write the parser in PHP 5, which has a great new set of tools for XML, but a lot of sites out there are still on PHP 4 (including mine), so the parser is PHP 4 friendly.
I’ve noticed my old rss-functions-mod.php file being re-used by folks in other WordPress plugins. That code doesn’t work with the new version of WordPress (I didn’t bother to investigate why, since I was done working on the new parser anyway). If you’re someone who’s used that file in your plugin, you may want to switch to the parser that’s included with Shashin 1.2. But you’ll need to make some adjustments to your plugin, as the data that comes out of the new parser is in a different structure.
Stay tuned for version 1.3, probably in a few weeks. I’m planning to include Highslide integration! 