This weekend I decided to add a photoblog plugin to my WordPress. It is hard to believe that I started this blog 18 months ago in December 2007. Unfortunately, I really haven’t had much time to play around with it to get it to do the things I’d like it to. Not to mention the keep up with the changes WordPress has undergone in that time. Typically the only time I play with my own sites is when I’m not feeling well. Something about working with code on something non-work related is semi-relaxing to me. Thanks to the major change in my schedule due to having a son in middle school my sleep schedule is completely off which means I fought with migraines this past weekend… and so I played with my WordPress blog – demented I suppose…
One of the first things tackled was a backup and install of the latest version. There is a great post on why to upgrade on WordPress.org. A quick way to tell if you’ve been affected by the worm is to look at your users’ page – if the number of admin users at the top is greater than the number you see when you click on the admin link, you’ve been affected… A more complete way is to go to your MySQL database and run an SQL query to show all accounts listed as administrator. This can be done either directly in the command-line MySQL client or by selecting your WordPress database in phpyAdmin and clicking on the ‘SQL’ tab to run the query.
SELECT u.ID, u.user_login
FROM wp_users u, wp_usermeta um
WHERE u.ID = um.user_id
AND um.meta_key = 'wp_capabilities'
AND um.meta_value LIKE '%administrator%';
If you use something other than the standard ‘wp_’ prefix for your table names you need to edit the above query…
Updates done, I decided to look at changing where I post my photo-a-day. I’ve been using pBase for many years but I would kind of like to change to something I have the control over so if I want to move it I can etc…
A trip to the Codex – lead me to Johannes Jarolim’s Yet another photoblog (yapb). If you are content with just the photos being shown on the posts (ie don’t want to show exif data or create lightbox links to the full size versions) the standard install of the plugin is very simple. The settings can edited on the WordPress dashboard under Settings -> YAPB.
Since I wanted to do something a bit different, I had to edit my theme files directly. Currently I don’t want different views on the home page, individual post page or archive pages; so instead of placing the code 3 times I created a yapb.php file and used include to place it in the 3 theme pages. After thought, I could have defined a new function for the yapb.php and then used a php get_yapb() call – I might change that in the future…
Johanne’s page on Adapting Templates is pretty straight forward. The only part I had to play around with to get to work is creating a link to the full image to use with Lightbox. The code I used for that is:
<a href="<?php echo $post->image->uri?>" rel="lightbox[photoaday]" title="<?php the_title(); ?>">
Next I decided to check out the YAPB Sidebar Widget. Having created this blog so long ago, my theme wasn’t Widget Aware.. shame on me! So off I went back to the Codex and Widgetizing Themes.
Pretty straight forward… but wait… it says, “See? We just added two lines to the template and now it’ll display a dynamic sidebar if possible, otherwise display the old sidebar.”
Well if you just add the:
<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar() ) : ?>
There is one little problem – you have an open php if statement! So – you also need to add:
<?php endif; ?>
at the bottom as well. Anything between these two pieces of php code will be eliminated if you use any widgets – if you want to just keep your current sidebar and just at a single widget – well don’t put any of your current sidebar code between the two parts 😉
Also remember to update your functions.php file:
<?php if ( function_exists('register_sidebar') ) register_sidebar(); ?>
Finally, while playing around with setting up yabp I was constantly editing a single post – starting with WordPress 2.6 every edit of a post creates a new row in the sql wp_posts table.
To turn off this feature, add the following to wp-config.php:
You can also go in and run a query on your SQL tables via phpMyAdmin to remove all post revisions (be sure to back up your SQL tables first!)
DELETE a,b,c FROM wp_posts a LEFT JOIN wp_term_relationships b ON (a.ID = b.object_id) LEFT JOIN wp_postmeta c ON (a.ID = c.post_id) WHERE a.post_type = 'revision'
I think that is all for now…
Stumbled across your blog googling around for YAPB related stuff. Didn’t really find what I was looking for, here, but your blog is overally pretty much worth a visit anyway. 🙂