Archive by Author
Adding Custom Post Types to the navigation menu in WordPress (3.1)
30th
March
2011
Posted by James Beattie - under News 7 Comments
Custom Post Types in WordPress are awesome! However, making them appear in your main navigation menu is difficult (and until now, some might have said impossible without hacking the WordPress core files). So after days of stumbling, reverse engineering and swearing, I present a solution which works nicely and involves just adding a filter to your theme functions file.
The following function will automatically grab all your custom post types (which are set to hierarchical= true) and add them to the main nav. You should ensure your custom post type has has_archive set to true also, as the archive page will be the main nav item, with all items in the custom post type appearing as children of this main item.
The way this function is written, it writes a Home link, it then loops through the custom post types adding the archive page as the main item and the items as children pages of the archive page. Then it loops through and writes the normal page menu, so your menu will end up looking something like this:
HOME | POST TYPE 1 | POST TYPE 2 | PAGE 1 | PAGE 2 | PAGE 3
This is by no means a complete solution, but hopefully it’s a starting point and will save someone the days of work it took me to come up with it.
Add the following code to your function.php file in your theme folder:
function custom_page_menu($menu, $args) {
// get supplied args
$list_args = $args;
// Overide some menu settings
$list_args['echo'] = false;
$list_args['title_li'] = '';
$list_args['show_home'] = false;
$list_args['exclude'] = 4; // excluding the homepage as I am manually adding it to the start below
// get the current page object as we will need to refer to it when setting current items below
global $wp_query;
$current_page = $wp_query->get_queried_object();
// Show Home item at the start of the menu
$menu .= '<li ' . $class . '><a href="' . home_url( '/' ) . '" title="' . esc_attr(__('Home')) . '">' . $args['link_before'] . __('Home') . $args['link_after'] . '</a></li>';
// Loop through the custom post types and add them to the menu
foreach(get_post_types(array(
'public' => true,
'_builtin' => false,
'hierarchical' => true
)) as $pt) {
$obj_pt = get_post_type_object($pt);
$list_args['post_type'] = $pt;
$menu .= '<li><a href="/' . $obj_pt->rewrite['slug'] . '/">' . $obj_pt->labels->name . '</a><ul>';
// little bit of hacking here to force wp_list_pages to add current classes to
// active pages in the generated navs. It's messy, but it means not hacing to
// hack the WordPress core files
$original_is_posts_page = $wp_query->is_posts_page;
$wp_query->is_posts_page = true;
$menu .= wp_list_pages($list_args);
$wp_query->is_posts_page = $original_is_posts_page;
$menu .= '</ul></li>';
}
// Now add the normal page collection which belongs in the nav
$list_args['post_type'] = 'page';
$menu .= wp_list_pages($list_args) ;
// glue the menu together and send back
if ( $menu )
$menu = '<ul>' . $menu . '</ul>';
$menu = '<div>' . $menu . "</div>\n";
return $menu;
}
add_filter( 'wp_page_menu', 'custom_page_menu' ,10,2 );
ASP.NET is almost certainly the wrong technology for your website project
18th
September
2010
Posted by James Beattie - under Developer, News 19 Comments
Often, when we are pitching for new website projects, one of the requirements specified by the client is that we build the site using Microsoft’s .NET (“Dot Net”) technology.
This request is a usually the result of the company I.T manager/CIO/ Systems Administrator/Consultant recommending a solution to stakeholders which they are familiar with.
In many cases, it is bad advice and should be ignored!
For simplicity’s sake, throughout the rest of this article I shall refer to your I.T Manager/CIO/Systems Administrator/Consultant as your “I.T Expert”.
.NET in a nutshell
In early 2002, Microsoft released their next generation of web application technology – the .NET framework. This superseded the old ASP (Active Server Page) technology which until then, had been Microsoft’s key technology for building dynamic, database driven websites and web applications.
.NET was not just an updated version of ASP – it was a completely rewritten, far more powerful and complex development framework which embraced the Object-Oriented approach to programming and introduced a new paradigm for building web applications using Microsoft technologies.
Since the initial launch of .NET, the framework has been improved, features added and more sophisticated tools for building and maintaining websites with .NET have been made available. The most notable of these being Microsoft Visual Studio, a complete IDE (Integrated Development Environment) for building websites with .NET
Your I.T Expert only knows Microsoft Technology
Before I begin, I want to make it clear that I am not implying that your IT Expert is incompetent. I will even go so far as to say that your IT Expert is possibly the best in their field and knows their technology inside out. (I also want to make it clear that this is not an anti-Microsoft rant, we use and love Microsoft products on a daily basis!)
The issue here is that most corporate I.T Experts administer predominantly Microsoft-based systems and technology: Windows Servers, Windows XP/Windows 7 Workstations, Microsoft Outlook, Microsoft Office (Work, Excel and Powerpoint), Microsoft Access Databases etc
They are often Microsoft-certified, are comfortable and familiar with the Microsoft technology, have a Microsoft rep who visits them regularly, they go to Microsoft launches, and generally live and breathe Microsoft on a day to day basis.
Thus, when called upon to provide their expert advice on a proposed website project, their immediate response is “built it in .NET”.
The problem here is that even thought your I.T Expert is very skilled in looking after corporate I.T environments, they most likely know very little about building and maintaining websites and web applications. It is just not a skill that is generally required by your I.T Expert.
The end-result of this is that companies spend a lot of time and money building web projects in .NET which could have been built faster, more cost effectively and with more flexibility using alternative technologies.
The problems with .NET
Overhead
.NET is very big and very powerful. It is used to build large corporate applications. This power comes with an overhead though. For most websites it is the equivalent of using a front end loader to move a few handfuls of dirt.
Expense
.NET applications usually use Microsoft SQL Server as the back end database. SQL Server is very powerful, and also very expensive. Again it is way more grunt than most websites/web applications need. It also requires IIS, Microsoft’s web server. This kind of hosting is more expensive, and performs less well, than its open-source counterparts.
Rapid Development
Modern web development is about fast, iterative development cycles. .NET is quite rigid and makes rapid development much harder. This leads to longer development cycles, overdue projects and blown budgets.
Search Engine Optimisation
The rigid structure of .NET makes Search Engine Optimisation harder to perform. Compromises often have to made in SEO strategies to accommodate the shortcomings of the framework.
Standards Compliant Code
It is difficult, if not impossible, to generate fully standards-compliant HTML using the .NET framework. If you care about good quality code, this becomes a real problem.
Javascript-based postbacks
.NET uses a mechanism called “Postbacks” for many of its interactive features. Unfortunately Postbacks require Javascript to be enabled in the browser using the site/application. This presents accessibility issues for internet devices without javascript and for disabled users.
Usability
Even though this is not directly a fault of the framework, for some reason .NET application are far more likely to contain critical usability problems. This is probably a cultural issue to do with the development tools and the developers themselves rather than the framework, but nonetheless it needs to be a consideration when building a website or web application.
Compiled Proprietary Code
.NET code for web projects is often compiled before deployment, with the source code being controlled by whoever originally developed the project. This essentially binds you to the vendor that built it. When you try to move to another vendor, often the original vendor will refuse to supply the source code.
Sometimes .NET is the right technology to use
There are some scenarios where the selection of .NET is appropriate. These would be situations where a website needs to integrate tightly with some kind of internal corporate systems which are built in .NET.
If this is your situation, then this could be a good reason to consider .NET. Although, even in this scenario, it is not a compelling reason. .NET makes exposing web-services very easy, so even when tight integration is required, this can be achieved through a web-service layer (which also adds a layer of abstraction and security between the website and the internal application).
Conclusion
We would encourage you to be sceptical when advised to use .NET for the purpose of building a website or web application project. In all likelihood this is not the right tool for the job.
Don’t ask for my credit card number for a free trial
1st
December
2009
Posted by James Beattie - under News 4 Comments
Offering a free, limited time trial for a software product or online service is not a new trend, however a recent development is vendors requesting credit card details before access to the trial is possible.
I recently decided to check out Audible, a service that supplies audio books for portable audio devices. They are a regular advertiser on my favourite podcast, Security Now, so after hearing a recent offer on this podcast for a free Audio Book, I decided to give it a go.
The initial free trial page is friendly and attractive, and simply asks for your name, email address and country:

This is all fair enough, so I entered my details and then I was presented with this page:

As you will notice, there is a payment section here requiring my credit card number to continue with the free trial. You may also notice the small link just above the credit card payment form titled “Why do you need my credit card information for a free trial?”. Clicking on this link presents the following pitch:
Our free trial offer is valid to customers new to Audible. Entering your credit card ensures that your AudibleListener® membership service will continue uninterrupted. In addition, it helps prevent abuse of our special offers. Cancel your trial within the trial period and your card will not be charged.
I have a problem with providing my credit card details for the following reasons:
Internet Security
I never give out my credit card online without a very good reason. In this age of internet fraud and identity theft any provision of my credit card to an online provider is made with due dilligence. A provider has to earn my trust first.
I am not willing to provide my credit card to get access to a trial version of a service that I may or may not choose to continue after the trial.
If a vendor has confidence in their offerings, they should not need this reassurance upfront. I also don’t like vendors storing my credit card details at all I would prefer to manually enter them at the time of payment and not have any online systems keeping a record of them in some possibly vulnerable database.
I am forgetful
I may sign up for trial version now and then forget to cancel it, even though I have no intention of using the service. With some vendors, if you do not cancel it before the trial verison is over, you suddenly start getting charged for the service you are not using. I think this is the real reason these vendors want your credit card upfront – because it gives them the ability to start billing you the moment they can. (I don’t know whether Audible is one of these services, as I did not proceed with the trial verison specifically because of this matter).
I think this a fundamentally unethical approach to earning revenue and I would encourage vendors not to ask me for my credit card number at the start of a “free” trial. I would even go further and encourage vendors not to store customer credit card data at all – there are other approaches that do not risk your customers credit card data.
Use a web-designer, not a print-designer to design your website
17th
September
2009
Posted by James Beattie - under News 2 Comments

Many traditional advertising agencies are, by neccessity, now moving into the web design and web development space. This makes perfect business sense considering the large amount of money which is being refunneled from traditional advertising methods into online advertising and marketing.
An unfortunate side-effect of this is that graphic designers with a background in print are now passing themselves off as web-designers without doing the requisite study/training/self-education to move to the new medium. The problem with many print designers is they do not understand the intricacies of working within web browsers. They are used to their design being exactly represented when it comes out of the printing press.
Tags: Design
Symfony Tip: Admin Generator + sfGuardPlugin + SfGuard Profile
5th
August
2009
Posted by James Beattie - under News 1 Comment

If you get the error “Call to undefined method BasesfGuardUser::addsfGuardUserProfile” when using a custom sfGuardUser profile, you need to add the following method to the file /plugins/sfGuardPlugin/lib/model/sfGuardUser.php
public function addsfGuardUserProfile()
{
if(!$profile = $this->getProfile())
{
$profile = new sfGuardUserProfile;
$profile->setUserId($this->getId());
}
return $profile;
}
I know it sucks to hack a core plugin file, but sometimes we must pragmatic!
Symfony Tip: Propel pager with group-by returns incorrect total
27th
June
2009
Posted by James Beattie - under Developer 2 Comments

A quick tip for those getting incorrect record totals (and thus broken paging) when using the propel pager in Symfony:
Add the following method to your pager object:
$pager->setPeerCountMethod('getGroupedCount');
Then create the following method in your peer class:
public static function getGroupedCount($c)
{
$copy = clone $c;
// this should be the intended grouping column
$copy->addGroupByColumn(parent::ID);
return parent::doCount($copy);
}
Your pager will now work the way you want it to!
Managing your personal online reputation
13th
June
2009
Posted by James Beattie - under Writing 1 Comment

We recently recommended to a client that they set up a page on their website promoting themselves (and optimised for their name) so that people searching for them in Google would get this page as (hopefully) the first result.
The client expressed some concerns about putting themselves out on the web as a personal brand, and we thought some of the issues that were brought up were worth a mention here.
Tags: brand management, online marketing, reputation management, search engines, tips
sfJqueryFormValidationPlugin – A client-side form validation plugin for Symfony
1st
June
2009
Posted by James Beattie - under Developer 18 Comments

Jimmyweb is proud to present our first plugin for the Symfony Framework!
The plugin is called sfJqueryFormValidationPlugin (yes it’s a mouthful) and a beta version is available now from the plug-ins section of the Symfony website.
This plugin adds much-needed client-side form validation to sites built with the new(ish) Symfony forms framework. Presently, you can only specify server-side validation rules in a Symfony application – so our plugin parses the server-side rules into a format which can be understood by the jQuery Validation plugin, which in turn utilises the exceptional jQuery javascript library.
This essentially means that you get client-side form validation in your Symfony applications with no additional work whatsoever.
In a recent project, I had to build client side validation manually for a Symfony project with a number of large forms. The validation alone took two days to build and test. This plugin would have reduced two days of development from this project, had it existed then (in fact this was the catalyst for the production of the plugin in the first place).
This plugin is still in Beta, however we are running it successfully on a couple of production websites so far. We would encourage Symfony developers to give it a try and come back to us with bugs, suggestions, enhancements or comments.
In the future we are looking to add extra features such as accessibility enhancements and features to make forms more attractive.
Tags: development, javascript, jQuery, plugin, symfony
Using virtual machines
11th
May
2009
Posted by James Beattie - under Developer 1 Comment

For the uninitiated, Virtual Machines (VM’s) are a software and/or hardware solution which simulate a completely separate computer environment on an existing computer.
This ‘Virtualized’ environment acts as if it were a second computer sitting next to your current computer .
This technology allows you to, for example, run a different operating system from within your current one. (E.g You can run Windows XP in a Virtual Machine from within Windows Vista).
Tags: virtual machine, vm
Cloud computing in the modern office
9th
February
2009
Posted by James Beattie - under Jimmyweb 2 Comments
Someone recently said that cloud computing is like teenage sex – talked about more than actually done. And usually done badly.
Having recently set up our office in Sydney, we decided to do more than just talk about it (cloud computing that is). As a startup company, we need technology which is cost effective and requires very little ongoing maintenance.
In this vein, we implemented the following technologies for our office:
Tags: cloud computing, gmail, skype, subversion, tips