The Friendly Web Guys

The Jimmyweb Blog

Adding Custom Post Types to the navigation menu in WordPress (3.1)



Posted by - 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:


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
 '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



Posted by - under Developer, News 21 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


.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.


.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.


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).


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



Posted by - 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.

What is Rupert Murdoch up to?



Posted by - under News 2 Comments


Over the past week there has been a bit of buzz online about Rupert Murdoch’s plans for the future of News Limited’s websites. In a recent interview with Sky News, Rupert said he was thinking about removing his websites from Google and placing his news articles behind a paywall, available only to subscribers of his websites.
…Read more after the jump »

The Satisfaction of Leaving



Posted by - under Jimmyweb No Comments

The Satisfaction of Leaving

Ok, so I might be drawing a long bow to say that this post has anything to do with web design and development, but bear with me.

I’ve been banking with the same regular, normal bank since I was a child. There’s never been any real  incentive to change banks, no matter how frustrating the bank behaves, because, well basically, you still end up using another bank. Its kind of like voting. It doesn’t matter who you vote for, you still end up with a politician! In this case, it doesn’t matter who you bank with, you still end up having to deal with a bank.

Well that’s all changed.

…Read more after the jump »

Beyond the web – Real world analytics



Posted by - under News No Comments

Beyond the web - real world analytics

Anyone who has used Google Analytics knows just how awesome and useful the software can be.  Anonymously tracking users to your website, gathering data on site usage, discovering traffic trends, Google Analytics is a wonderful tool for any business on the web.

After doing some Analytics work for a website today, I started thinking about how brilliant it would be if businesses could use the same data in the real world. Some kind of geo-tracking analytics that could give real-time, real world feedback to businesses.

Could this be the future?

…Read more after the jump »

10 tips for businesses starting out with Twitter



Posted by - under Writing 3 Comments

Twitter for business

There’s been a lot of buzz about Twitter recently in the media, so its natural to want to know what all the fuss is about, and learn more about how Twitter might benefit you, both personally and in business.

I thought it might be a good idea, to put together a quick beginners guide to Twitter for our clients, and a list of my top 10 tips for using Twitter in business, to help you understand the basics of Twitter, and how you can use Twitter to help your business.

So what is Twitter?

Twitter is a social communication network that asks the question: “What are you doing now?” Users can answer via the Twitter website, sms, mobile phone application or a desktop application. Twitter updates (commonly referred to as ‘tweets’) have to be under 140 characters in length.

Its natural to think that you couldn’t possibly say anything meaningful in 140 characters, but the quality of communication is actually quite surprising, once you become familiar with using Twitter. Unlike writing a blog, Twitter is a great place to tell the world what you’re thinking before you’ve had a chance to even think about it.
…Read more after the jump »

Agile Design – Quickly moving from Photoshop to CSS



Posted by - under Design 1 Comment


I recently read a post over at 37 signals about why the designers there skip Photoshop in the design process and I found myself agreeing with most of the conversation. There are some good reasons for designing this way, along with some good counterpoints.

The Photoshop mockup just isn’t a website.

A while back I used to always fully develop a design in Photoshop, with all the polish and finesse that could possibly fit into a flat two dimensional image and present the design to the client for approval.

This worked reasonably well when the only real interaction was the click of a hyperlink or perhaps a drop down menu. You could explain the functionality, describe the interaction and hope the client had the imagination to perceive the concept clearly enough to approve it.

…Read more after the jump »

Use a web-designer, not a print-designer to design your website



Posted by - 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.

…Read more after the jump »

Symfony Tip: Admin Generator + sfGuardPlugin + SfGuard Profile



Posted by - 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;
    return $profile;

I know it sucks to hack a core plugin file, but sometimes we must pragmatic!