Comment Feature Back Again
When I first created this theme, I contemplated between having or not having the comment function implemented. In the end I went with a blog without the comment feature; Only the trackback function was enabled.
I initially thought the contact form was good enough as a means of communication, and that if no one knows how to use it, they don’t deserve to be using the internet. But I was told that to use the contact form for a simple comment would be overkilled. In addition to that someone asked for me to put up the comment section again. So I set out to think of ways to make my comment section different from the default layout yet fool-proof.
I thought for awhile and decided to make the comment page a separate page, meaning one whole page just for posting comments. The idea sounded easy, but it was actually more work then I expected it to be. For someone who had absolutely no prior knowledge to PHP, it was almost like making James Bond follow the law; Not impossible, just hard.
I searched online and came across a site that explained exactly what I wanted to do, but the instructions were pretty messy and static, so hopefully my version of instructions will be of use to anyone who wish to do the same.
In my version, you will be editing 5 files instead of the original posts’ 3 files, and with the link to the comments page left untouched. Files from your current theme folder will be:
- single.php
- functions.php
- comments.php
The 2 other files will be from your /wp-includes directory.
- comment-template.php
- link-template.php
Theme Folder
- First step is to go into your themes folder and open up the folder of your current theme.
- Open up single.php and wrap the following code around your single post syntaxes, within the loop
<?php if (!isset($_GET['show'])) { ?>[single post codes here]<?php } ?>
- Next, look for
<?php comments_template(); ?>and replace it with the following code
<?php if (isset($_GET['show']) && $_GET['show'] == "comments") { ?><?php comments_template(); ?><?php } ?>
- You can now go ahead and close your single.php file after saving your changes.
- Now open up your functions.php file and add the following function.
function curPageURL() {$pageURL = 'http';if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}$pageURL .= "://";if ($_SERVER["SERVER_PORT"] != "80") {$pageURL .= $_SERVER["SERVER_NAME"].":" .$_SERVER["SERVER_PORT"] .$_SERVER["REQUEST_URI"];} else {$pageURL .= $_SERVER["SERVER_NAME"] .$_SERVER["REQUEST_URI"];}return $pageURL;}
- Save your changes and open up your comments.php file and add the following code before the
</form>tag, which is usually near the end of the file
<?php if (function_exists('curPageURL')) { ?><input type="hidden" name="redirect_to" value="<?php echo curPageURL() ?>" /><?php } ?>
You’re done editing your theme files. Next we’ll move on to the wp-includes directory.
/wp-includes
- Open up your comment-template.php file
- scroll to line 487. Replace
#comment-with:
?show=comments#comment-
- Scroll to line 498. Replace
#commentswith:
?show=comments#respond
- Scroll to line 964. Replace
#respondwith:
?show=comments#respond
- Scroll to line 1023. Replace
#with:
?show=comments#
- Scroll to line 1074. Replace
#$respond_idwith:
?show=comments#$respond_id
- Scroll to line 1153. Replace
#comment-with:
?show=comments#comment-
You’re now done with comment.template.php. Moving on…
- Now open up link-template.php
- Scroll to line 1511. Replace
#commentswith:
?show=comments
- Scroll to line 1625. Replace
#commentswith:
?show=comments
If everything went well and accordingly, the <?php comments_popup_link(); ?> function should now link to your comments page by appending ?show=comments#respond to your single post permalink rather than just #respond.
If any of you noticed, the trackback link that was previously under every post has been taken away. The reason for that is because I still have yet to figure out how to put trackbacks on a page by itself because posting it as a comment will be a mess and in addition to that, trackbacks have no avatars, therefore ruining my whole comment section design.