November 23, 2008

Removing Comments from WordPress Classic Theme

Filed under: Hacks,Reference/Learning — Tags: , , , — Jayx @ 11:42 pm

The WordPress Classic Theme is one of my favorites (also the one used for this site), because it is simple and easy modify to your own taste. By default it is a fluid lay-out with absolute positioned sidebar (right) but with very little effort you can get it to look just about right.

The one aspect that is rather annoying though, is that when you disable comments on post or page, it still displays the comments footer and a message that comments are not allowed at present. Somewhat ugly if you create pages that you do not want your readers to comment on. “No problemo” says my friend and uber-l33t codemonkeyCharlVN and goes about hacking the theme.

You can view his post here … this is how you edit the comments.php file to stop displaying those pesky messages. See also code below – basically you have to remove lines that start with a “-” and add the lines that start with a “+”; the rest of the markup will help you find your way through the document. You will need to open the comments.php file in a text editor – the quickest, fail safe way is to highlight the complete line that needs to be removed and do a replace find/replace.

 <p><?php _e('Enter your password to view comments.'); ?></p>
 <?php return; endif; ?>

-<h2 id="comments"><?php comments_number(__('No Comments'), __('1 Comment'), __('% Comments')); ?>
+<?php if ( get_comments_number() > 0 || comments_open() ) : ?>
+       <h2 id="comments"><?php comments_number(__('No Comments'), __('1 Comment'), __('% Comments')); ?>
+<?php endif; ?>
 <?php if ( comments_open() ) : ?>
        <a href="#postcomment" title="<?php _e("Leave a comment"); ?>">ยป</a>
 <?php endif; ?>

 </ol>

-<?php else : // If there are no comments yet ?>
+<?php elseif ( comments_open() ) : // If there are no comments yet ?>
        <p><?php _e('No comments yet.'); ?></p>
 <?php endif; ?>

-<p><?php post_comments_feed_link(__('<abbr title="Really Simple Syndication">RSS</abbr> feed for comments on this post.')); ?>
+<?php if ( comments_open() || pings_open() ) : ?>
+<p>
+<?php if ( comments_open() ) : ?>
+       <?php post_comments_feed_link(__('<abbr title="Really Simple Syndication">RSS</abbr> feed for comments on this post.')); ?>
+<?php endif; ?>
 <?php if ( pings_open() ) : ?>
        <a href="<?php trackback_url() ?>" rel="trackback"><?php _e('TrackBack <abbr title="Universal Resource Locator">URL</abbr>'); ?></a>
 <?php endif; ?>
 </p>
+<?php endif; ?>

 <?php if ( comments_open() ) : ?>
 <h2 id="postcomment"><?php _e('Leave a comment'); ?></h2>
@@ -71,6 +78,4 @@

 <?php endif; // If registration required and not logged in ?>

-<?php else : // Comments are closed ?>
-<p><?php _e('Sorry, the comment form is closed at this time.'); ?></p>
 <?php endif; ?>

Not all that difficult; even I could do it :) basically the post is now not only checked for comments, but also if comments are disabled or not and the result is a much neater looking theme.

spread the word
  • Google Bookmarks
  • muti
  • StumbleUpon
  • TwitThis
  • Facebook
  • Digg
  • laaik.it
  • del.icio.us
  • Technorati
  • Reddit

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment

Powered by WordPress. WP Classic Theme adapted by jayx. Valid XHTML 1.0 Transitional.