For a long time now a thing that troubles many webmasters puzzled me too. I have a few articles that bring in what you would call “instant visitors”, meaning visitors that get what they want and they are out of here. Those come either from search engines or bookmarking sites (digg, stumbleupon etc). I was surprised to see that when querying for “file not accessible bin”, which is a common problem when trying to mount a bin image in daemon tools, brings this blog first on the list. I can see through the stats that i get quite some traffic from a few posts like that but i hardly get even a comment.
Now the suggestion from all bloggers is “try to lure that reader in”. Others suggest poping up a window with a subscribe or something. Others suggest to put on a “if you like this post subscribe to my feed” etc. What i wanted is actually grab the visitors attention when he first comes in. If he gets the info he wants your blog tab will be closed in a glimpse of an eye.
I had my eyes open for a plugin or something out there suggesting something remotely close to this but no luck so far. I was too lazy to code a plugin myself. The other day i was thinking about it and it came to me. I can use custom fields to do that! So here is what i came up with…
So i guess you have seen that part on the “write” section where it says “custom fields”. But here is what they are. Actually, they are extra attributes that can be added to your post. Just anything you want it to be! For instance, the series plugin uses them for adding a post into a series. The “featured” article plugin uses them to decide which articles are “featured”. But how can you use them? Simple. You don’t need no plugin no nothing. What you do is define a “key” and a “value”. Imagine this example. You want to add your mood, when writing your post, into your post. For that, you can create a key called “mood”. In each post you can add the key “mood” and a value like “happy”, “bored” etc.
So, all i wanted is to characterize a post as “hot” and if so then add a few relative categories that the user might be interested to. If a post is hot i want to add a box on top of the post, before the title. A message will be in there, pointing the user to the relavtive categories i set. Using custom fields i could add key/value pairs like “rel_cat” -> “7″ (7 beeing the category “Misc”), “rel_cat” -> “10″ (10 beeing the category “Tutorials”) etc. Then it’s the theme’s turn.
In the presentation part, except for the box on the post, i want to add a “(Hot!)” small text near the title. Let’s start from there. I opened my index.php file and i modified this line:
which is actually the line that displays the title of the post to this:
As you can see i added a small php frag that handles the “hot” field. The most important thing to notice is this function: “get_post_meta($post, $tag_key, $single)”. This function, for a given post ($post), brings the value of the key ($tag_key). In the above, i bring back the value of the key “hot” and if there is one and it’s “1″ then the post is hot and i should display the “hot” tag. When a user visits the post i want to add the box i was talking about. You can see an example here. Basicaly, what i want to do is:
Here i will show you my single.php file (which is the one in charge for single post rendering) and the css rules i created.
On the file single.php, before the title, i added this code snippet:
Take a minute and look at the code. Nothing fancy here. I check to see if it’s hot. If so, i start the box, adding a text and listing the categories. Simple huh?
Now on the css we have these:
Now, all the above are always left open for tweaking according to your needs. I really wish this one helps you lure your visitors a bit deeper. I will start monitoring how it goes for me and maybe post the results for you guys. In the meantime, any suggestions/fixes etc are always welcome!