Want to know when there are new posts?

SUBSCRIBE VIA EMAIL

SUBSCRIBE VIA RSS

Tagged: ‘Code’

Aug 7th

Separate Your Trackbacks From Your Comments

It is amazing how many blogs do not do this. They have the messiest comments section with a zillion comments, trackbacks and pingbacks all jumbled up. And it is almost impossible to make some sense of out of the entire mess. Want to follow the conversation? Try evading the trackbacks and pingbacks along the way.

What’s the solution?

Separate the two, of course.

But How?

That’s a good question. You will find plugins that do this but if you can manage something in the theme design, it is best to do so rather than install plugin upon plugin. Plugins are best used where you cannot achieve your objective without touching the core Wordpress files.

In this case all you need to work with is your theme’s comments.php file.

Step One - Counting Comments and Trackbacks

Since the normal comment count includes both the comments and trackbacks, we first need to get a separate count for each.

Find this line in comments.php

<!-- You can start editing here. -->

Add the following code under it

<?php
$numTrackBacks = 0;
$numComments = 0;

foreach ($comments as $comment) {
$comment_type = get_comment_type(); 
if ($comment_type != 'comment') { $numTrackBacks++; }
else { $numComments++; }
}
?>

Basic gist:
First we set $numTrackBacks and $numComments as 0. We then check the database and loop thru the comments and trackbacks. If the record retrieved is not a comment then a number is added to the trackback count otherwise the comment count is increased.

Step Two - Showing the Comment Count

Next we need to show the comment count before we display the comments.

Find this line

<?php if ($comments) : ?>

and add this code after it:

<?php echo $numComments;?> 
<? if ($numComments = 1) :?>
Response
<? else : ?>
Responses
<? endif; ?>
to &#8220;<?php the_title(); ?>&#8221;

This will spit out the comment count in this format:
1 Response for ‘Post Title’
5 Responses for ‘Post Title’

Step Three - Displaying The Comments

Next we have to display comments. Look for this line:

<?php foreach ($comments as $comment) : ?>

And add these two lines after it:

<?php $comment_type = get_comment_type(); ?>
<?php if($comment_type == 'comment') { ?>

What we are doing here is checking to see if the record retrieved is a comment.
If so then we display it.

Since we have opened a loop, we also need to close it.

Find the line

<?php endforeach; /* end for each comment */ ?>

and replace it with:

<?php } /* End of is_comment statement */ ?>
<?php endforeach; /* end for each comment */ ?>

We have successfully displayed our comments without any trackbacks or pingbacks.

Step Four - Displaying Trackbacks and Pingbacks

Time to display our trackbacks and pingbacks.

Add this code right after you finish displaying the comments (in most themes it would be after the /ol tag):

<? if ($numTrackBacks != 0) :?>
<br />
<h3>Trackbacks and Pings 
(<? echo $numTrackBacks; ?>)</h3>
<? endif; ?>
<ol>
<?php foreach ($comments as $comment) : ?>
<?php $comment_type = get_comment_type(); ?>
<?php if($comment_type != 'comment') { ?>
<li><?php comment_author_link() ?></li>
<?php } ?>
<?php endforeach; ?>
</ol>

You can change the styling and format to suit your site. However, this basic code will show your trackbacks and pingbacks separated from your comments.

Now there is no excuse to not clean up your blog and organize your comments.

No Comments Subscribe To RSS Feed

Topics: All Things Wordpress Code

Aug 6th

Adding Live Preview For Comments

If you scroll down you will see a live preview option for comments. Just try it out by typing in a comment. Pretty cool, huh!?

A friend asked me why this was useful and why anyone will want to see their comment twice?

My answer: If your comment is pretty long, the textarea will start to scroll and you won’t be able to look at your entire comment in on go. The preview on the other hand shows the comment in its entirety. This way you can see how it looks and proof read with ease before you post.

I have gotten this technique from the Rockatee Blog. So a big thank you to Maleika.

  1. First things first. You need to download jQuery. Lets just name it jquery.js and place it in your theme folder.
  2. Next download this file and place it in your theme folder.
  3. Now open header.php from your theme and add these lines in the head area:

    <script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/jquery.js"></script> <script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/preview.js"></script>

  4. Last step is to add the following code to you comments.php file wherever you want the live preview to show up.

    <div class="comment-preview"> <h3>My Comment Preview</h3> <p class="live-preview">Add some instructions - this text will get replaced by the comment preview.</p> </div>

  5. You can use the class p.live-preview to style the live comment preview.

See that was simple and you have your own comment live preview.

4 Comments Subscribe To RSS Feed

Topics: All Things Wordpress Code

Aug 3rd

CForms II - The All In One Contact Form Solution

Cforms II is a Wordpress plugin which makes it easy for you to add a contact form to your website.

Once you install and activate the plugin, don’t get intimidated by the dozens of options available. It is pretty easy to set up. Click on CForms from your WP admin menu.

Click to view bigger image
Click to view the bigger image
Continue Reading »

6 Comments Subscribe To RSS Feed

Topics: All Things Wordpress Code

Aug 1st

A Little Hack to Get Your Password Back

This can either be a very useful or a very dangerous trick depending on how it is used or abused.

I found this little tip at: FiddyP (it’s a really cool blog btw).

It only works in Firefix and boy does it work!

If you have a stored password that you can’t remember and all you can see are asteriks, just add this line to the address bar:

javascript:var els = document.getElementsByTagName('input'); for(var x=0; x<els.length; x++){ if(els[x].type.toLowerCase() == 'password' ){ var test = els[x].type = 'text';}}

Press enter and wait to be pleasantly or unpleasantly surprised to see your password staring back at you.

No Comments Subscribe To RSS Feed

Topics: Code

Jun 29th

Adding Code To Your Wordpress Post

Trying to add code to your wordpress post can be one of the most frustrating experiences. That is if you want the code to appear as code in your post.

Say, something like this:

<ul><li>This would have been a bullet</li></ul>

Had this been added to Wordpress normally, it would have appeared as a bullet. But since I’ve used a really cool plugin called ‘Code Auto Escape’, I can add code as code as long as I add pre and code tags around it.

Now you may never need to show html, xhtml, javacript, php, etc code in yuor posts but just in case you do, this is the plugin to get.

Get the Code Auto Escape Plugin

No Comments Subscribe To RSS Feed

Topics: All Things Wordpress Code

Nov 13th

Most Useful Wordpress Plugins

Since I design custom blogs for my clients, I have to keep a lookout for plugins that can achieve any effect under the sun. Following is a list of some of the most used plugins:

  1. Akismet: This plug-in helps you in stopping comment spam. It also keeps note of comments you mark as spam for future blocking. This is a part of your Wordpress download. You need to install and set it up, though.
  2. Search Everything: This plug-in adds search functionality to include pages, tags, attachments, drafts, comments, excerpts and custom fields. It also lets you exclude categories and posts from search.
  3. WP-Contact-Form: Give your visitors the option of contacting you via a simple form. The modified version of this plugin comes with a very useful Spam Protection option. See an example
  4. Add This: Social Bookmarks allow your visitors to easily submit your posts to social bookmarking sites. Many plugins are available for this purpose including Social Bookmarks, Gregarious and Sociable. I just recently found Add This and although it adds a link to their site, it is less intrusive and less cluttered than the others. You can see the result at the end of this post.
  5. All in One SEO Pack: The name says it all :) You won’t need another meta title, description or keyword plugin. This finally has it all.
  6. Video Plugin: Easily add videos from YouTube and many other websites.
  7. Google Sitemap Generator: Generate an xml sitemap for Google. This will help with Google spidering your website.
  8. Database Backup: Weekly backup at your server or back up emailed to you.
  9. Search Meter: Looking at search logs to find out who’s searching for what can be a valuable tool for figuring out what’s right and what’s wrong with your blog.
  10. Permalink Redirect: This plugin ensures that pages and entries are always accessed via the permalink. Otherwise, a 301 redirect will be issued. In other words saves you from the duplicate content penalty in Google.
  11. Fuzzy Recent Posts: Displays recent posts
  12. Recent Comments: Displays recent comments and/or trackbacks
  13. Google Analyticator: No need to dig in the code to add Google Analytics to your blog with this plugin. It does the work for you.
  14. Subscribe to Comments: Lets your visitors subscribe to comments for whichever post they want. Try subscribing to the comments for this post to see how it works.
  15. Related Posts: Using the Wordpress tags option in Wordpress 2.3.1, this plugin gives a list of related articles/posts next to the currently viewed one.

You can see a lot of these plugins being used at this website alone. I plan on adding more useful plugins as I come accross them so don’t forget to sign up for the RSS feed. There is also an email option once you click the link.

You can also browse thru the Wordpress Plugins Directory. There are loads of great plugins listed there with ratings and other useful info to help you pick the right ones.

1 Comment Subscribe To RSS Feed

Topics: All Things Wordpress