Housekeeping note: Now with syntax highlighting

I haven’t posted a lot of code on this blog, but I have started to find the plain text formatting used up to now is not as readable as it could be. Since this site is a WordPress install, it seemed sensible to take a look at the Plugin Directory to see if I could do anything about this. And I can.

WP Code Highlight provides syntax highlighting and, handily, uses the <pre> and </pre> to establish where to apply the highlighting.

I have, therefore, installed it, tinkered around with the settings and then adjusted the theme settings to accommodate it. I may make a few minor tweaks if I spot any glaring inconsistencies but, for now, I am pretty happy with the way things are starting to look.

Housekeeping

Much as I liked the Ghostwriter theme, it really did struggle to handle inline images properly and after a couple of months of intending to have a crack at the CSS, I have finally admitted to myself that I don’t have the time. So I have gone back to the Arjuna-X theme that I was using when I started this blog.

In other news, I have deactivated the Google +1 plugin. It was messing with my layout.

Themes

Just a short post to let you know that I’m playing around with Worfdpress themes at the moment, There is a lot to explore and I am still interested in seeing if I can knock together something that more closely relects my own preferences.

I’m using the default theme for now, but this will probably change – frequently – over the next few weeks.

WordPress galleries and Lightboxes

Often, when I start looking for a WordPress plugin to achieve something I find that the functionality I need – or much of it – is already included in the core code. The WordPress Gallery is a case in point.

So here’s the requirement: I want to add several pictures to a post, automatically formatted into a thumbnails gallery allowing visitors to click on the thumbnails to see the full size images. This can be achieved with no additional functionality at all. All you need to do is upload the pictures into an existing post using the Add An Image button.

The point to remember here is that, when you upload each image, you do not want to Insert Into Post. Use the Save All Changes button instead. This will add the image to your gallery – you can see the image count rise at the to of the Add an Image Window.

As soon as you have added two or more pictures, WordPress will start displaying Gallery Settings every time you upload an image. These settings are reasonably self-explanatory. If, once all your images are uploaded, you click on the Insert Gallery button you will see the following shortcode in your post:

[gallery]

And the result looks like this:

There are several options you can use, described here, and by default clicking on an image will take you to the permalink page for that image – essentially the full sized image but surrounded with the styling used across your blog.

You can, however, go a stage further and add a Lightbox. The one I have found to work most nicely is the jQuery Lightbox For Native Galleries which has a demo-page here. This displays the images in a pop-up without leaving the post and… It’s just a bit prettier.

Pulpmovies upgrade and merging WordPress blogs. Some final thoughts

A month after deciding to merge all of the sections of Pulpmovies onto a single platform, the deed is done. Much of it went pretty well although I did encounter some glitches along the way.

The parts of the process that relied on WordPress functionality (exporting the blogs and importing them into the new site) went remarkably well and, by reorganising the categories beforehand I had very little to do once everything was merged.

It did take significantly longer than expected for two reasons. Firstly, I hadn’t fully taken account of the sheer number of files that needed to be deleted. More significant, however, was that my hosting provider enforces a maximum upload size of 8MB which I could find no way around. Since several of the exported blogs came in at a lot bigger than this, I had to chop them up in order to upload them. Cutting the files down to size wasn’t difficult, but Gedit was probably not the best tool to use in this instance.

One thing I did notice, however, is that the exported files include all comments – including those marked as spam. This undoubtedly is what sent some of the file sizes through the roof and, if I was ever to try something like this again, I think it would probably be wise to delete all the spam comments from the blog before exporting it.

But that’s for the future.

I went with an off-the-peg theme in the end although I have started tinkering with it and will need to make some more changes before I am completely happy. But for now, I shall have some dinner and treat myself to a well deserved beer.

Merging WordPress blogs – but only for selected categories

With WordPress, merging blogs is easy but things get a little more interesting if you only want to merge a selection of categories from the old blog with the new. Here’s a way to do it.

First of all, you need to create a temporary user in WordPress to which the posts can be assigned. You can use whatever name you like, but the name I used was xfer.

Then we need to start hacking the database with whatever your preferred SQL client happens to be. The table prefix in the scripts below is wp_ yours may be different.

-- Script 1
-- Identify the ID for the xfer user
-- Make a note of this, you'll need it later.
SELECT *
FROM wp_users
WHERE user_login = 'xfer';

-- Script 2
-- Identify your categories to be assigned.
-- For each of the categories you want to assign, make a note of the term_id
select * from wp_terms;

-- Script 3
-- Sanity check. This script will list the posts that you are about to reassign
-- You don't need to run it...
-- but I like to know what I'm about to change before I make the change
-- The (60, 42, 44, 36, 63) is the list of term_ids for the categories to reassign,
-- from Script 2
select *
from wp_terms a
join wp_term_taxonomy b on a.term_id=b.term_id
join wp_term_relationships c on b.term_taxonomy_id=c.term_taxonomy_id
join wp_posts d on c.object_id=d.ID
where a.term_id in (60, 42, 44, 36, 63)
and post_status='publish';

-- Script 4
-- Change the author for the posts in the selected categories
-- The 86 is the ID for the xfer user.
-- Use whatever value you retrieved from Script 1
-- The (60, 42, 44, 36, 63) is the list of term_ids for the categories to reassign,
-- from Script 2
update wp_posts
set post_author=86
where ID in
(select c.object_id
from wp_terms a
join wp_term_taxonomy b on a.term_id=b.term_id
join wp_term_relationships c on b.term_taxonomy_id=c.term_taxonomy_id
where a.term_id in (60, 42, 44, 36, 63))
and post_status='publish';

Once this is done, you can go back into WordPress and export just the posts assigned to user xfer.