Spice Up Wordpress with Resizable Comment Boxes

Skill

Spice Up Wordpress with Resizable Comment Boxes

Posted in:

It doesn't matter where you are, comment boxes never seem to be the right size for what you're trying say. A great way to fix the problem is to let the user resize the comment box to fit their needs. This tutorial is going to demonstrate how to take our resizable textbox and incorporate into your installation of Wordpress.

The style of Switch On The Code is based on a heavily modified version of the Bitter Sweet theme. All-in-all we've really enjoyed this theme - except when it comes to the comment box. It was made a little too small and we've never gotten around to fixing it - until now. Sure we could have simply edited the theme files to make the box bigger, but where's the fun in that?

Wordpress Resizeable Textbox Screenshot

Isn't that beautiful?

First off, we really wanted to make this a plugin for Wordpress, but it doesn't look like the plugin system easily supports changes to the comment box - it's more of a theme thing. That means to actually use resizable textboxes we're going to have to get our hands dirty modifying the theme's source files. Fortunately, The Tallest designed the textbox to be nice and modular so the code required is as small as possible.

The first thing we need to do is find the PHP file to modify. The file is called "comments.php" and is stored in your theme's folder inside the Wordpress "themes" folder. I know that sounds confusing, so here's a picture to help clear things up a little.

Wordpress Folder Structure

As you can see, the file I had to modify was stored in the folder, "bitter-sweet-10". Yours will be located in the folder for whatever theme you've decided to use.

Now that you've found the file to modify, we need to find what part of the file to change. This can be wildly different depending on how your theme was implemented, but basically you need to find the textarea inside this file. For our theme, it was located on line 124.

<p>
  <textarea name="comment" id="comment" cols="100%" rows="10" tabindex="4>
  </textarea>
</p>

All we have to do is replace that line with our resizable textbox code.

<script type="text/javascript" src="/Resizable_Textbox/javascript.js"></script>

<link rel="stylesheet" href="/Resizable_Textbox/style.css"
   type="text/css" media="screen" />

<span id="commentContainer"></span>

<script type="text/javascript">
   var rt = new ResizeableTextbox();

   rt.SetCurrentWidth(290);
   rt.SetCurrentHeight(200);
   rt.SetMaxWidth(525);
   rt.SetMaxHeight(600);
   rt.GetTextArea().id = 'comment';
   rt.GetTextArea().name = 'comment';

   var mySpan = document.getElementById('commentContainer');
   mySpan.appendChild(rt.GetContainer());

   rt.StartListening();
</script>

Pretty simple, right? We simply added the Javascript file, CSS file, a container object, and a few lines of Javascript code and everything is up and running. The resizable textbox will be placed inside the span tags by the Javascript code. We chose to use a span because now when the box is resized, the contents below the page will move up and down with the textbox. All the files referenced here can be downloaded from the Resizable Textbox tutorial posted earlier. I'm not going to go into any details on what those few lines of Javascript code are doing - if you want to know, I would suggest checking out that tutorial.

And that's it for making your Wordpress comment box resizable. You can check out the results for yourself by leaving us a comment.

Update: November 13th, 2007

We simplified the process of adding the resizable textbox. You can now put in the following code instead of what is listed above. Hopes this makes things easier.

<script type="text/javascript" src="/Resizable_Textbox/javascript.js"></script>

<link rel="stylesheet" href="/Resizable_Textbox/style.css"
   type="text/css" media="screen" />

<span id="rtContainer">
   <script type="text/javascript">
      var rt = new ResizeableTextbox('comment');
      rt.SetCurrentWidth(290);
      rt.SetCurrentHeight(200);
      rt.SetMaxWidth(525);
      rt.SetMaxHeight(600);
   </script>
</span>

TJE
12/07/2007 - 20:47

Sick... we were just searching for this. Thanks for posting in such detail. You can see the original version above - it looks horrible.

out...

reply

Luke
03/11/2008 - 07:24

ye good but it doesnt work on my site, can this work in dreamweaver?

reply

Luke
03/11/2008 - 07:30

and please please meake it clearer

reply

Dee
05/16/2008 - 09:27

hey just testing nice box thing

reply

Tln
11/10/2008 - 17:01

nice! can u explain clearer, because this works only on my test pages (html and php) but not with wordpress!?

thanks

reply

Tln
11/10/2008 - 17:11

ok, it works, thanks!

reply

Toby Simmons
12/06/2008 - 11:34

Love this addon, and it's beautiful to boot. The only problem I am having with it is that you cannot tab into the field, at least using IE7. It probably has to do with the absolute positioning of stuff. Anyway, thanks for a cool addon!

Cheers,

Toby

reply

Toby Simmons
12/06/2008 - 11:36

Well, let me rephrase that ... the tab order is kinda funky. It appears at the end of the DOM, so it shows up after everything else, not where intuitively it appears it should be (after the Website textbox.)

Cheers again!

Toby

reply

Toby Simmons
12/06/2008 - 11:58

Okay, I swear I'm not spamming you! You can fix it easily by including the following:

rt.GetTextArea().tabIndex = 4;

reply

The Tallest
12/07/2008 - 14:38

Thanks for the info, Toby! I never thought to make sure that tab navigation worked properly - glad you caught it and were able to fix it.

reply

Yah
07/07/2009 - 00:35

testing only

reply

Anonymous
01/24/2010 - 04:51

Hi,

My wordpress blog isnt allowing any comments, when you click for comments you get redirected to 'page not found'. What is wrong? My blog is at http://www.workwithclairegalea.com

Would be really gratyeful if someone can help me!

reply

khurrammushtaq@hotmail.com
02/28/2010 - 11:26

Not working :(

reply

Anonymous2
06/16/2010 - 15:50

No mail?

reply

Add Comment

Put code snippets inside language tags:
[language] [/language]

Examples:
[javascript] [/javascript]
[actionscript] [/actionscript]
[csharp] [/csharp]

See here for supported languages.

Javascript must be enabled to submit anonymous comments - or you can login.

Sponsors