Running WordPress on Mac OS X with XAMPP
- Download XAMPP for Mac OS X from http://www.apachefriends.org/en/xampp.html.
- Open the xampp dmg file and copy xampp into the applications folder.
- Run the xampp control app and start apache & mysql.
- Using your browser, go to http://localhost/xampp/splash.php
- Select your language then click phpMyAdmin.
- Create a database called ‘wordpress’ using ‘utf8_unicode_ci’ collation.
- Download WordPress from http://wordpress.org/download/.
- Unzip WordPress into /Applications/XAMPP/htdocs/.
- Copy the following details into your wp-config file, and save it as wp-config.php These are the exact details you need for Xampp to work because the default user in phpmyadmin is called ‘root’ and there is no password:
- DB_NAME is ‘wordpress’.
- DB_USER is ‘root’.
- DB_PASSWORD is ”.
- DB_HOST is ‘localhost’.
- In your browser, go to http://localhost/wordpress/wp-admin/install.php to install WordPress.
- Once WordPress installation is complete go to http://localhost/wordpress/ to verify the installation.
- To get automatic updates of WordPress and installation/updates of plugins and widgets working do the following:
- Make a note of your username e.g. ‘Daniel’.
- Open /Applications/XAMPP/etc/httpd.conf as root/admin e.g. “sudo open -e ‘/Applications/XAMPP/etc/httpd.conf’” from terminal.
- Find the following lines:
User nobody
Group admin - Change the lines to the following:
User <Your Username>
Group staf f - Save the file.
- Restart XAMPP and visit http://localhost/wordpress/ you should now have a fully functional WordPress installation you can experiment on without effecting your live blog.
The next step is to mimic the configuration of the live blog on the test blog by:
- Importing the posts and comments from the live blog.
- Installing the same theme, widgets and plugins.
- Configuring the theme, widgets and plugins.
You can now start hacking away on your test blog without worrying about breaking your live site!
WordPress filters for Google Analytics
If you use Google’s excellant Analytics service to track traffic to your WordPress blog you may have noticed that days were you have been doing a lot of administrative work or writing on your blog that you had large traffic spikes. This is due to Google Analytics recording all your administrative and writing related visits to your site and this can be quite misleading if your trying to improve your traffic.
Fortunately there is a very simple way to configure Google Analytics to prevent administrative pages and post preview pages being recorded as genuine site traffic.
- Login into Google Analytics.
- Click the ‘Analytics Settings’ option in the top left:

- Click the ‘Edit’ option for your blog’s site:

- Click the ‘Edit’ option for the ‘Main Website Profile Information’ section:

- Enter ‘preview=true|wp-admin’ into the ‘Exclude URL Query Parameters:’ textbox and click ‘Save changes’:

Google Analytics will now ignore all visits to WordPress’es administrator pages (which are in the ‘wp-admin’ subfolder on a typical install) and also ignore any page previews (which have ‘preview=true’ in the URL). You can now administrate your site and write posts without worrying about your actions skewing you site’s traffic data!
DIY Social Bookmarking buttons in WordPress
I recently redesigned the theme I am using for this blog and one of the things I’m happiest about is that the social link buttons are now in the footers of my posts along with the tag, category and poster information. This is where I’ve always wanted these buttons to live and I thought that how I achieved this may be of interest to others.
I’ve wanted to add link buttons to the end of my tops for social bookmarking sites like Digg, StumbleUpon and reddit, etc for a while now but never quite managed to get the syntax correct when trying to build the links myself in php. Recently I discovered the excellent sociable plug-in for WordPress that allows you to add link buttons for almost sixty different social bookmarking sites to the end of your posts, which is very handy. However I was not a great fan of where these buttons were inserted: right at the end of the text body of the post.
I decided I’d really prefer the buttons be placed in the post footer area for each post, so I started looking through the source of the sociable plug-in to see how it generated its links and it turns out it was pretty simple. The following php function is what I ended up with. It will build link buttons for five social bookmarking sites: del.icio.us, digg, reddit, stumbleupon and technorati.
function my_social_links() {
$post = $wp_query->post;
$permalink = urlencode(get_permalink($post->ID));
$title = urlencode(get_the_title($post->ID));
$title = str_replace('+','%20',$title);
$templateDir = get_bloginfo('template_directory');
echo '<a href="http://del.icio.us/post?url='.$permalink.'&amp;amp;amp;amp;amp;amp;title='.$title.'">';
echo '<img src="'.$templateDir.'/images/delicious.png" title="del.icio.us"/>';
echo '</a>';
echo '<a href="http://digg.com/submit?phase=2&amp;amp;amp;amp;amp;amp;url='.$permalink.'&amp;amp;amp;amp;amp;amp;title='.$title.'">';
echo '<img src="'.$templateDir.'/images/digg.png" title="digg"/>';
echo '</a>';
echo '<a href="http://reddit.com/submit?url='.$permalink.'&amp;amp;amp;amp;amp;amp;title='.$title.'">';
echo '<img src="'.$templateDir.'/images/reddit.png" title="reddit"/>';
echo '</a>';
echo '<a href="http://www.stumbleupon.com/submit?url='.$permalink.'&amp;amp;amp;amp;amp;amp;title='.$title.'">';
echo '<img src="'.$templateDir.'/images/stumbleupon.png" title="StumbleUpon"/>';
echo '</a>';
echo '<a href="http://technorati.com/faves?add='.$permalink.'">';
echo '<img src="'.$templateDir.'/images/technorati.png" title="Technorati"/>';
echo '</a>';
};
The programmers amongst you will notice the recurring pattern in how the permalink and title are concatenated into the required URL format for each site. And that the interesting bit of code is the first part where the post permalink and titles are retrieved and then URL encoded so they can be embedded into the links. I added the above function to my functions.php file, so I can access it from anywhere and I currently call it from the loop on my main index page and on the single post pages.
I’d also like to recommend using the SyntaxHighlighter plug-in for WordPress for your code highlighting needs as it is more wordpress compatible and does not have issues with the TinyMCE editor stripping out tags or replacing ‘ with %27.
Adding filtering to the ‘Recent Comments’ WordPress widget
I recently started using WordPress‘s dynamic sidebar functionality for the side column on this blog which contains things like lists of recent posts, recent comments etc. My main motivation for doing this was to get access to the ‘Recent Comments’ widget so I could list the most recent comments on my posts.
To activate the widget and the dynamic sidebar I did the following:
- Logged into the WordPress admin dashboard.
- Clicked on the ‘Design’ tab.
- Clicked on the ‘Widgets’ sub tab.
- Added a sidebar.
- Enabled the ‘Recent Comments’ widget.
- Clicked save changes.
- Reloaded my blog’s main page in another browser tab and noted the normal side bar had disappeared to be replaced by the sidebar that currently contains only the ‘Recent Comments’ widget.
- I then added some other widgets to replicate the original functionality in my original sidebar.
I then noticed that my ‘Recent Comments’ widget contained not only user comments but trackbacks and pingbacks too, this was annoying as I only want user comments to be listed and nothing else. After some searching around the web for a simple solution, followed by some experimental tweaking of the WordPress source code, I can now present the simplest solution I could make to filtering out all non-comment comments from the ‘Recent Comments’ widget:
- Open your WordPress installation folder via ftp or locally.
- Open the ‘wp-includes’ directory.
- Make a back up copy of the ‘widgets.php’ file, just in case.
- Open the ‘widgets.php’ file.
- Search for the following line in the function ‘wp_widget_recent_comments’ (it was at line 981 in version 2.62 of WordPress): $comments = $wpdb->get_results(“SELECT comment_author, comment_author_url, comment_ID, comment_post_ID FROM $wpdb->comments WHERE comment_approved = ’1′ ORDER BY comment_date_gmt DESC LIMIT $number”);
- Make the following addition (in red) to the line: $comments = $wpdb->get_results(“SELECT comment_author, comment_author_url, comment_ID, comment_post_ID FROM $wpdb->comments WHERE comment_approved = ’1′ AND comment_type = ” ORDER BY comment_date_gmt DESC LIMIT $number”);
- Save the modified file.
- Upload the updated file to your web server.
- Reload your blog’s main page, you should now only see comments in the ‘recent comments’ list.
For those that are interested in what this change actually does, here is an explanation. The line of php code we are changing queries SQL database that is part of your WordPress installation and searches the comments table for the latest user specified number of approved comments. The addition we are making adds an extra clause to the SQL query that searches for the latest approved comments: this extra clause specifies that we are only interested in comments when the comments table’s comment_type column has the value ” which is the value WordPress uses to designate user comments and not trackbacks or pingbacks.
Note: This change was made and tested with WordPress version 2.6.2, I don’t know how well it will work with older versions of WordPress. Also if you upgrade your WordPress installation you will need to make the above change again, unless the new version already implements it.








