Phew. Seems like I have finally found the time to write this tutorial, although I have been intending to write it for ages now. Since my WordPress system already runs on a whole bunch of Plugins (some more useful than others, I can assure you) I did not really feel like adding another one to create my own WordPress-powered guestbook, especially not when the same can be done easily by just some tiny bit of coding. So, I dived into the WP Templates and found an easy, simple and understandable way to turn an ordinary page into a Guestbook.
First, go into your Theme Editor (I’m assuming you know your way around WP atleast a little) and check your template files. You will notice one of the files in called Page Template. Hint: You can search for it in your FTP Programme, there it is entitled page.php and typically residents somewhere in your wp-content/themes/ folder. In case this file is not present (what the heck? How does your blog even work?) it is time to make one. In this example, I will use the default Page Template to keep things easy. Most ordinary Page Templates have the same coding, so it will not differ a lot anyway.
<?php get_header(); ?><div id=”content” class=”narrowcolumn”><?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class=”post” id=”post-<?php the_ID(); ?>”>
<h2><?php the_title(); ?></h2>
<div class=”entry”>
<?php the_content(’<p class=”serif”>Read the rest of this page »</p>’); ?>
<?php wp_link_pages(array(’before’ => ‘<p><strong>Pages:</strong> ‘, ‘after’ => ‘</p>’, ‘next_or_number’ => ‘number’)); ?>
</div>
</div>
<?php endwhile; endif; ?>
<?php edit_post_link(’Edit this entry.’, ‘<p>’, ‘</p>’); ?>
</div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
This is how the Page Template looks like in the default WP Theme. In most themes, the class tag (narrowcolumn) is dropped, but apart from that it is most likely to look exactly the same. Now, lets dig into the Page Template. By some small amount of thinking, we can easily conclude that this is the Template WordPress automatically searches for and uses when we create a page. What the WP Codex also tells us that we can, in the Page Editor, select a different page template than the default one. So, if we would like a certain page, such as our Guestlog, appear a little different than the other pages (which we do), all we have to do is create a new page template, using the exact same coding, change some bits here and there and add a title to it. Now, it did not take me too long to come up with that one, but I can understand that some people might look at their screen by now thinking: What in God’s name are you talking about? So, I’ll tell you step by step.
First, copy your Page Template theme into an empty file. In case you do not use a special, fancy HTML Editor, NotePad is still the most popular programme for Windows users (since I don’t own a Mac, I don’t know what standard programme is present there used for HTML coding). By copying I mean, open the page.php file, select everything in it, click right and select copy, then go to your empty NotePad file and paste. That should not be too hard, now, eh? In case you cannot find your Page Template or something, you are welcome to copy the code presented earlier in this tutorial too
Next, we will have to give the template another name. If we skip this step, it is most likely that it will simply replace our ordinary Page Template. We don’t want that. I choose the convenient name of “Guestlog” for it, but you can also play around with names a little, ranging from “Guestbook” to “Visitor Log” to “Davy Jones’ Locker” but I suggest you keep it clean and easy, so you don’t forget later on why you created that special Page Template. Now you have thought of a name for your super spiffy page, here’s how you should add it. Simply add the following under your <?php get_header() ?> tag:
<?php
/*
Template Name: Guestlog
*/
?>
You can choose the Template Name to whatever name you picked. In case you do not really know where exactly to put it, here’s an example of how the beginning of your Guestbook Template coding should look like.
<?php get_header(); ?>
<?php
/*
Template Name: Guestlog
*/
?>
<div id=”content”>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
Now, we have coded a page that will serve as our guestbook. However, if we just sticked to the regular page coding, there would have been no need to create a special Template for it. Of course, the geniuses amongst you will have figured out by now that there will be another few bits of coding that will have to be edited. Thank God that the WordPress Pages already have comment features, or life would be a whole lot more complicated for us (as would this tutorial be). Simply add the following line above the <?php endwhile; endif; ?> tag.
<?php comments_template(); ?>
This will load your default comments template, causing both a comment form to show up as well as comments. Basically, that is all a guestbook needs. For those having trouble locating where exactly to put the Comments Template calling code, here is an example of how the Guestlog page should look like eventually. (When you use the Page Template of the default WP theme.
<?php get_header(); ?>
<?php
/*
Template Name: Guestlog
*/
?>
<div id=”content” class=”narrowcolumn”>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class=”post” id=”post-<?php the_ID(); ?>”>
<h2><?php the_title(); ?></h2>
<div class=”post-content”>
<?php the_content(’<p class=”serif”>Read the rest of this page »</p>’); ?>
<?php link_pages(’<p><strong>Pages:</strong> ‘, ‘</p>’, ‘number’); ?>
</div>
</div>
<?php comments_template(); ?>
<?php endwhile; endif; ?>
</div><!–/content –>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
Save your file as guestbook.php or guestlog.php or whatever you want to call it, as long as it has the extension .php and does not have the same name as one of the files already present in your theme. Now, since I have the Paged Comments Plugin enabled (which you should do too: it automatically reverses comments, therefore putting the latest first and every 10 comments you can go to a next page, which is what guestbooks really need) this is where my journey ends. In case you do not enable the Plugin, I suppose your Comments Template needs a few more tweakings here and there, but I’m not getting into that since I have not really tried it myself when creating my Guestlog.
Now we have reached the final steps of our journey in Guestblog land. All there is left for us to do now, is go to the Write menu in the Admin Panel, choose Write Page and type an intro for our Guestbook. For example: Welcome to my Guestlog place. You are free to sign my Log if you see fit, but please refrain from Spamming it. Do not forget to enable comments (would be silly to have a Guestbook no-one can comment on) and choose Guestbook as template. Publish.
Now your Guestlog should be ready. A small word of advice still though: guestbooks even more than comment systems have the tendancy to fall victims to SPAM. Of course this is a true disaster, but there are various WP Plugins out there that can prevent SPAM. If you enable them, they will automatically work on your Guestbook page as well. I recommend you Spam Karma 2, Bad Behaviour and Akismet. Preferably all three of them.
I hope this tutorial helped you out and you were able to quickly create your own Guestbook without using any Plugins whatsoever. If however, you do not understand parts of the tutorial or it simply does not work for you, etc. you are free to ask questions on this thread. Please refrain from asking such questions in my Guestlog though
Which you can, btw, view here. Enjoy.
Recently Reviewed
Fatal error: Call to undefined function goodreads() in /home/elvenmys/public_html/x/wp-content/themes/glossyblue/footer.php on line 19