A small update to the site’s functionality (and learn some PHP!)

Comment functionality

There has been so much to write about, however I have been beyond busy especially with the quarter drawing to a close. There is a showcase to plan and schedule for, and industry people will be there so I want my students to shine. From what I’ve seen, they will. On top of that I’m mentoring a group for a business competition and of course there’s the regular teaching, grading, meetings and other stuff that goes on.

Nevertheless, it had been nagging at me that the site’s comment functionality never worked quite right. I’ve been made aware of it before, so why it started to gnaw at me two weeks ago I’m not certain, but it did. What I wanted it to do was give visitors an option of commenting via WordPress login, Facebook, Twitter, or other social media accounts they may prefer rather than having to sign up specifically with WordPress. Normally on a WordPress site there is an option for this, however for whatever reason – and I never understand why WP themes do this – my theme overrode this, forcing visitors to log in through WordPress if they wanted to comment (hence one of the reasons for the dearth of comments). You can see how it should look in the header image. Luckily, the fix was beyond easy, but shows the lengths the theme designer went through to ensure a broken commenting system.

Here’s what I had to do to fix it. You aren’t going to believe it, but here we go:

WordPress uses a file called ‘comments.php’ to provide comment functionality. Here’s what my original comment.php file looked like:

<?php if ( post_password_required() ) { ?>
<p><?php _e( ‘This post is password protected. Enter the password to view any comments.’, ‘themater’ ); ?></p>
<?php return; } ?>

<?php if ( have_comments() ) { ?>
<div id=”comments”>

<h3 id=”comments-title”><?php
printf( _n( ‘One Response to %2$s’, ‘%1$s Responses to %2$s’, get_comments_number(), ‘themater’ ),
number_format_i18n( get_comments_number() ), ‘<em>’ . get_the_title() . ‘</em>’ );

<ol class=”commentlist”>
<?php wp_list_comments(); ?>

<?php if ( get_comment_pages_count() > 1 ) { ?>
<div class=”navigation clearfix”>
<div class=”alignleft”><?php previous_comments_link( __( ‘<span class=”meta-nav”>&larr;</span> Older Comments’, ‘themater’ ) ); ?></div>
<div class=”alignright”><?php next_comments_link( __( ‘Newer Comments <span class=”meta-nav”>&rarr;</span>’, ‘themater’ ) ); ?></div>
</div><!– .navigation .clearfix –>
<?php } ?>

</div><!– #comments –>
<?php } ?>

<?php comment_form(); ?>

A lot there, yes? You may be wondering if the comments functionality needs all that PHP, and the answer is no. Actually, it’s because it was all there that the comment functionality was broken in the first place. In fact, to INCREASE the functionality of the comment system and allow people to comment using any social media login they prefer, I had to make the following changes. Be sure to pay very close attention, because the change is subtle and hard to notice; see if you can see it in the new code:

<?php comment_form(); ?>

Did you see it? You may want to read through it again to be sure. I’ll wait.

So there you have it. By deleting the entirety of what was there before and only leaving the final line, full functionality was restored, the attempts at subverting the proper order of things was thwarted, and all is right with the world. Now, anyone who wants to leave a comment can do so in a way that is quick and easy, just like the code that allows it.

Going Up