Lost!This sleepy Saturday afternoon I logged into my blog, saw there were two comments awaiting approval, noted both were SPAM. So, I marked them that – and purged them permanently. There was a warning sign that I should have made note of, but did not until after the permanent deletion. Instead of two, 20 comments got deleted – meaning along with 2 SPAM ones, 18 meaningful ones got deleted as well.
BAM!!! I value each comment, as they sometimes add significant value to the content of the post. I was lost – what do I do?
First thought was to check my backup – I maintain a backup of my blog, however in this case the backup was more than 6 months old while these comments were less than a month old.
Not losing heart, I realised my hosting provider might have a backup. However, the provider is based out of US and had not opened yet. I left them a message. Reading the FAQ I thought I might have a chance if I can get in touch with them quickly. They only maintained a copy of the most current data, hence contacting them sooner might save the day. That was not to be: they started work two hours later and then got back to me saying that the backup was about 30 minutes old – which is after the comments were deleted. Not good. I was in despair now.
It was time to go to sleep now, and there was barely anything more that I could have done. Next morning I woke up still with a feeling of sadness, and then I had a brainwave. I get an email whenever someone posts a message to my blog. This email contains the message posted. I could check my email box, search for these messages and repost them myself!!!
A quick search on my Nokia N97 revealed I still had those emails. Paradise regained!!!
When I wrote my first WordPress related post, I admitted that I was only doing it to attract traffic and it would be my last post on the subject. However, I start again. This time around, however, I want to talk about something which isn’t common knowledge and neither did I get any responses on the official WordPress forum regarding this.
Suppose you do not want some of your posts to appear anywhere: not the homepage, not the RSS feeds, not the archives: nowhere. However you DO want it to appear only when its linked to, as a single post on the page. I regularly need to do this, because some part of the post is more like an ‘addendum’ or when including everything would make the post too long.
There is a standard solution available on the forums: creating a plugin and adding code to this effect:
Here, 22 is the category number of the category I wanted to exclude.
This code works fine, but the moment you add is_category to the ‘if‘ clause, it doesn’t work for the category page. This was perplexing to me, and I did not understand it. I spent a long time and then decided to dig deeper. I found out that the ‘wiring’ is faulty (this is what I believe). It can’t work like this for the category page. What is needed additionally is something like this:
function hs_cat_exclude_cat($where)
{
global $wp_query;
if ($wp_query->is_category) {
$where = $where . " AND NOT EXISTS(SELECT 1 FROM wp_term_relationships WHERE wp_term_relationships.object_id=wp_posts.id AND wp_term_relationships.term_taxonomy_id='22')";
}
return $where;
}
add_filter(‘posts_where’,’hs_cat_exclude_cat’);
So far so good. What I wanted over and above this though, is for the category to not even appear on the category widget. I tried to find a way to get this done through the plugin but it did not work. Ultimately I had to ‘hack’ one of the core files to achieve this. If anyone knows of a better way to accomplish this, please add a comment. The change is to wp-includes/widgets.php. Find the line of code that looks like:
Update Jan 12th 2010: Since WP 2.8 I believe (I noticed the problem in 2.9.1), the last change above needs to be done to default-widgets.php rather than widgets.php
Adding a logo to the header generated by WordPress Default theme
When I started this blog, I did add categories ‘Computers‘ and ‘Programming‘. However, I made one decision: I will not cover HowTos on WordPress as part of this blog. The reason? There are at least two blogs for each WordPress related topic on earth. Yes, I know about giving back to the community (WordPress is free after all), but there are better ways in my opinion. The second reason was, have you ever noted someone talking on the Microphone about how to use the Mike? No, most people talk about other things, not about the Mike itself. Similarly, WordPress is a medium. A lot of the WordPress related blog posts are pilfered from elsewhere, even at times from WordPress.org 🙂
Yet, this is my first (and hopefully the only) WordPress HowTo. The reason is simple: I have come to realise that people come to blogs less to hear what is being said, and more learn how to speak their own thing. 🙂 So, being human, and wanting to hike my readership I have joined the bandwagon. At least this isn’t pilfered from anywhere.
Doing this is quite easy. Go to the folder /wp-content/themes/default/images under your WordPress folder. In this folder, locate the file called header-img.php. You should see a line of code written like this:
//die;
header("Content-Type: image/jpeg");
Add two lines of code above this, making it look as below:
Here, logo.png is your logo image which is also lying the same folder. The numbers 70, 50 are the coordinates of upper left corner where you want your logo to appear – experiment a bit to find out what looks best for your logo. The numbers 100,100 are the width and height respectively of your logo image.
Have a look at how the result appears for me: Logo Sample
Thats it! Easy – just try it and post any questions/queries/suggestions.
WordPress, the blogging platform that I use for this site has this as the motto: “CODE IS POETRY”. I really like it, and in truth, the way they have written the software – its a real treat. It only confirms the saying – best things in life come free. The design is modular and pluggable, database is well design and one feels nice reading through the code. As a side-effect, its easy to understand and maintain. When I was planning to make the first modification/plugin – I had imagined it would be a tough task – but it turned out to be not very difficult.
Its another matter that my own modifications to the code have made it look more like prose, and less like poetry!
Licensing and information about the blog available here.