Tag Archives: Wordpress

View Unread or New Comments in Disqus – WordPress Hack

The job here is to highlight unread or new comments that a visitor to your site has not seen. This is especially helpful when you have a blog with lots of threaded comments where it becomes difficult for a reader to get a grip on just where they should look to read new comments. This method can work anywhere, not just in WordPress, but this example is geared towards the Disqus WordPress Plugin. Once you install the plugin, find the comments.php file located inside the plugin folder, usually something like wp-content/plugins/disqus-comment-system/comments.php.

Open it up and find the following line of code:

<?php if (!get_option('disqus_manual_sync')): ?>

Right before that line, paste the following:

		config.callbacks.afterRender.push(function() {
			jQuery(function($) {
				var largestReadId = document.cookie.match ( '(^|;) ?largest_read_id=([^;]*)(;|$)' );
				largestReadId = largestReadId ? parseInt(unescape(largestReadId[2])) : 0;
				var newLargestReadId = 0;
				$('.dsq-comment-header').each(function() {
					id = parseInt($(this).attr('id').split('-')[3]);
					if (id > largestReadId) $(this).parent().css('background', 'lavender');
					if (id > newLargestReadId) newLargestReadId = id;
				var expiry = new Date();
				expiry.setTime(expiry.getTime() + 7 * 24 * 60 * 60 * 1000); // 7 days
				document.cookie = "largest_read_id=" + newLargestReadId +"; expires=" + expiry.toUTCString();


All we’re doing is setting a cookie storing the largest read disqus comment id per post in the user’s browser. If a comment id smaller than it is encountered, it’s left alone. If a bigger one is encountered, then we use jQuery’s parent() and css() functions to add some styling to the comment. You can change that line as you desire. You can see this feature implemented on Raptors Republic

Follow me on Twitter – @zararsiddiqi


What files changed in WordPress 2.8.4? The proper way to upgrade patches

I run raptorsrepublic.com which uses WordPress with some pretty heavy customizations here and there so every time WordPress releases an upgrade I’m very wary of doing it because I just don’t know how it’ll effect the platform. Partial file copying with FTP can really throw you a curveball and if one file gets corrupted it’ll take you hours to find out which one.

I think the best way of upgrading WordPress installations is by only copying files that changed over patch releases (e.g.: 2.8.2, 2.8.3 and 2.8.4). If there’s a database change things get a little more complicated but in most patch releases that’s not the case.

The way you find out what files were changed is by accessing the WordPress SVN repository and running the svn diff command. Here is the commands one need to run and the output that follows it. I’m running this on a Linux box with SVN installed. You could also do it in windows if you download the binaries.

svn diff --summarize http://core.svn.wordpress.org/tags/2.8.3/ http://core.svn.wordpress.org/tags/2.8.4/
M      http://core.svn.wordpress.org/tags/2.8.4/wp-login.php
M      http://core.svn.wordpress.org/tags/2.8.4/wp-includes/version.php
M      http://core.svn.wordpress.org/tags/2.8.4/readme.html

This means three files changed between the two versions as M stands for modified. That value could also be A for added and D for deleted. If you’d like to see what the actual changes were just get rid of the --summarize part. I copied these three files over to my WordPress installation and I’m done!

Integrating vBulletin with a WordPress theme

OK, so you have a WordPress blog and are thinking about adding a vBulletin message board to it and want it to appear seamlessly within your WP theme. This post will show you how to do it.

The way you go about accomplishing this is by creating two Plugins under vBulletin. Before we do anything we have to make sure that the Plugin/Hook system is enabled. For this select vBulletin Options under the vBulletin Options from the control panel. Select the Plugin/Hook System option in the select list and make sure its enabled. Once you’ve done that, you’ll need to create a couple plugins. Click on the Add New Plugin option under the Plugins & Products on the left hand side of the control panel. Create a plugin with the Hook Location specified as global_start and the default execution order. Give it the title of WP Header and in the Plugin PHP Code field, write the following:

   $wp_header = ob_get_contents();

Now let’s examine what I did here. Bascially, I’m invoking two WordPress PHP files, wp-load.php from the main installation and header.php from my theme’s directory. I capture the content of it in the $wp_header variable which we’ll use later.

Make sure you change the plugin to be active by clicking on the Yes radio button and save the plugin.

Now we’ll create another plugin for the footer. Once again, specify the Hook Location as global_start, give it the title of WP Footer and select the default execution order. In the Plugin PHP Code field write the following:

   $wp_footer = ob_get_contents();

In this plugin we’re capturing the theme’s footer.php in the $wp_footer variable.

Now we need to insert the two pieces of data we captured into the vBulletin theme. For that let’s go to Style Manager under the Styles & Templates group in the left control panel. Once there, select Edit Templates from the drop down list which should give you a listing of all the editable files in your theme. Double-click on header from the list and simply add the following line of code as the first line in the file:


Save it and go back to the list of editable files and edit footer. Make sure the following line of code is the last line in the file:


Save it and you’re done.

Well, almost. Depending on the version of vBulletin you have you might get a PHP error which says something like “sanitize_url function has already been defined”. Check the vBulletin file its happening in, download it and rename both occurrences of the function to something like vb_sanitize_url and now you’re done.