Keep a Page Out of the Breadcrumb Trail

Note: This guide is only valid for versions of Breadcrumb NavXT prior to 4.0. Since Breadcrumb NavXT 4.0 the bcn_after_fill action should be used to remove breadcrumbs from the breadcrumb trail.

In the past, several users have asked how to exclude certain pages from the breadcrumb trail generated by Breadcrumb NavXT. As with most programming problems, many solutions exist to this problem. Previously, one posted code that removed the breadcrumb from the bcn_breadcrumb_trail::trail array before calling bcn_breadcrumb_trail::display(). However, since the introduction of Breadcrumb NavXT 3.0 a much better solution exists. This method uses the inheritance principle of OOP and requires no editing of the distributed files.

Code in this tutorial was written against the SVN Trunk version of Breadcrumb NavXT (the basis or Breadcrumb NavXT 3.3.0). Therefore, any code contained herein will require some modifications to work with Breadcrumb NavXT 3.2.x. The general process, however, is the same for any version of Breadcrumb NavXT since 3.0.0. Also, note that you must have a PHP5 environment for this to work as it requires the PHP5 object model.

First, open the functions.php file of your theme. Within it we are going to create a new class named ext_breadcrumb_trail, and tell PHP that it is an extension of the bcn_breadcrumb_trail class. We’ll place the skeleton for the class constructor in at this time as well.

class ext_breadcrumb_trail extends bcn_breadcrumb_trail
{
	//Default constructor
	function __construct()
	{
		//Need to make sure we call the constructor of bcn_breadcrumb_trail
		parent::__construct();
	}
}

We need a way to get the IDs that will be excluded from the trail into the class. They could be hard coded into the class, but that is not very extensible (and a very bad coding practice). Instead, a public member variable named $excluded_ids will be added to store the IDs. Now, we should have the constructor accept IDs to exclude and store them in $excluded_ids. Our code now looks similar to the following:

class ext_breadcrumb_trail extends bcn_breadcrumb_trail
{
	public $excluded_ids = array();
	//Default constructor
	function __construct($excluded_ids)
	{
		//Set the value of
		$this->excluded_ids = $excluded_ids;
		//Need to make sure we call the constructor of bcn_breadcrumb_trail
		parent::__construct();
	}
}

Now that the IDs of pages to be excluded can get into the class, we need to do something with them. We want to override the function bcn_breadcrumb_trail::page_parents() since it does not know how to exclude pages. To start, we’ll copy the code for page_parents from the class bcn_breadcrumb_trail into our new class. This is the result:

class ext_breadcrumb_trail extends bcn_breadcrumb_trail
{
	public $excluded_ids = array();
	function __construct($excluded_ids)
	{
		$this->excluded_ids = $excluded_ids;
		parent::__construct();
	}
	/**
	 * page_parents
	 *
	 * A Breadcrumb Trail Filling Function
	 *
	 * This recursive functions fills the trail with breadcrumbs for parent pages.
	 * @param  (int)   $id The id of the parent page.
	 * @param  (int)   $frontpage The id of the front page.
	 */
	function page_parents($id, $frontpage)
	{
		$parent = get_post($id);
		//Place the breadcrumb in the trail, uses the constructor
		$breadcrumb = $this->add(new bcn_breadcrumb(apply_filters('the_title', $parent->post_title), $this->opt['page_prefix'], $this->opt['page_suffix']));
		//Assign the anchor properties
		$breadcrumb->set_anchor($this->opt['page_anchor'], get_permalink($id));
		//Make sure the id is valid
		if($parent->post_parent >= 0 && $parent->post_parent != false && $id != $parent->post_parent && $frontpage != $parent->post_parent)
		{
			//If valid, recursively call this function
			$this->page_parents($parent->post_parent, $frontpage);
		}
	}
}

Now, it’s time to modify the page_parents() function. We’ll use ext_breadcrumb_trail::excluded_ids and the PHP function in_array() to skip the breadcrumb insertion step for pages that are to be excluded from the trail. We do this by wrapping the two lines of code containing the variable $breadcrumb within a branch of an if statement. Within the if statement we’ll use $id and $this->excluded_ids as the parameters for in_array(). Since we want the branch to run if the ID is not an excluded ID, we’ll place the not operator (!) in front of in_array. At this point, we have the final version of our class that is ready to use.

class ext_breadcrumb_trail extends bcn_breadcrumb_trail
{
	public $excluded_ids = array();
	function __construct($excluded_ids)
	{
		$this->excluded_ids = $excluded_ids;
		parent::__construct();
	}
	/**
	 * page_parents
	 *
	 * A Breadcrumb Trail Filling Function
	 *
	 * This recursive functions fills the trail with breadcrumbs for parent pages.
	 * @param  (int)   $id The id of the parent page.
	 * @param  (int)   $frontpage The id of the front page.
	 */
	function page_parents($id, $frontpage)
	{
		$parent = get_post($id);
		//Check if the current page should be excluded
		if(!in_array($id, $this->excluded_ids))
		{
			//Place the breadcrumb in the trail, uses the constructor
			$breadcrumb = $this->add(new bcn_breadcrumb(apply_filters('the_title', $parent->post_title), $this->opt['page_prefix'], $this->opt['page_suffix']));
			//Assign the anchor properties
			$breadcrumb->set_anchor($this->opt['page_anchor'], get_permalink($id));
		}
		//Make sure the id is valid
		if($parent->post_parent >= 0 && $parent->post_parent != false && $id != $parent->post_parent && $frontpage != $parent->post_parent)
		{
			//If valid, recursively call this function
			$this->page_parents($parent->post_parent, $frontpage);
		}
	}
}

Next, we need to modify the breadcrumb trail calling code in the theme. Assuming that the theme directly calls the bcn_breadcrumb_trail class, very little has to be modified. We just replace all instances of bcn_breadcrumb_trail with ext_breadcrumb_trail in the calling code. Additionally, when creating the new instance of ext_breadcrumb_trail we need to feed in our array of IDs of pages to be excluded. An example calling code block is located below, in it pages with ID equal to 100, 230, or 231 will not show up in the breadcrumb trail except when they are the current page.

if(class_exists('ext_breadcrumb_trail'))
{
	//Make new instance of the ext_breadcrumb_trail object
	$breadcrumb_trail = new ext_breadcrumb_trail(array(100,230,231));
	//Setup options here if needed
	//Fill the breadcrumb trail
	$breadcrumb_trail->fill();
	//Display the trail
	$breadcrumb_trail->display();
}

In this tutorial we never modified any of the actual plugin files. This was made possible due to inheritance through the creation of a derived class. Since no plugin files were modified, upgrading to new versions of Breadcrumb NavXT are less likely to break the functionality. Finally, this method can easily be modified to exclude categories instead of pages from the breadcrumb trail (replace page_parents with category_parents).

-John Havlik

[end of transmission, stay tuned]

Windows 7 Versions for Dummies

People are already complaining about the six versions of Windows 7 that Microsoft will release. They should be reminded that Vista had the same number as did XP (Embedded, Starter, Home, Media Center, Tablet PC, Professional, Professional Corporate). The editions are Starter, Home Basic, Home Premium, Professional, Enterprise, and Ultimate.

Windows 7 employees a scheme more like XP originally was, either you’ll use Home Premium or Professional (Professional inherits all the features of Home Premium, unlike Vista Business). In Vista, not all of Home Premium’s features made it into Business edition, which left all users that wanted the Media Center features and Active Directory support with the overpriced Ultimate edition. Windows 7 Ultimate is more or less a non VLK version of Enterprise plus the Media Center features (I suspect the Media Center stuff will not be there in Enterprise despite claims of the contrary by others). End users in developed countries will never see Windows 7 Starter or Home Basic, and in most cases Enterprise.

Here’s a nice decision flow chart for those who are confused (and live in a developed country (e.g.,  USA, Canada, UK, Japan, etc.)):

Windows 7 Edition Selection Guide (for Consumers in Developed Countries)
-John Havlik

[end of transmission, stay tuned]

Installing WPN111 on Windows 7 Beta

They say it can not be done. I am here to prove them wrong. That is correct, you can run the Netgear WPN111 USB 802.11b/g card in Windows 7. It’s a little cumbersome, but possible. Here is how you do it. Note that you can leave the USB adapter plugged in during the entire process (that is what I did).

First, grab the latest WPN111 drivers from Netgear’s website. Then, right click and select “Run as administrator”. Continue on through the prompts, when it gets to the point of setting up networks use Task Manager to kill the installer. If you do not kill the installer, the finding networks portion will fail, causing it to automagically uninstall itself.

Now, open up device manager (right click on “Computer” select “Properties” and on the left sidebar click “Device Manage”). Under “Other devices” your WPN111 should show up with a nice warning sign. Select it, and right click, select “Update Driver”. Now select the “Browse my computer for driver software” option. Search in the location “C:\Program Files\NETGEAR\WPN111\Driver” for 32bit Windows and “C:\Program Files (x86)\NETGEAR\WPN111\Driver” for 64bit Windows. Then press “Next” if everything goes correctly, near your clock the WiFi signal icon will show up.

This method was tested on a 64bit install of Windows 7 Beta 1. It should work on 32bit installs as well. Though it seems to work, a few words of advice. First off, do not use WEP, instead use WPA or WPA2. I was unable to get WEP to work on this particular card in Windows 7. Also note a Netgear prompt may show up on startup, do press “Accept” and then tell it you want to use the “XP” wireless manager. If you fail to do this you will have to redo the driver installation.

-John Havlik

[end of transmission, stay tuned]

Gentoo and an Aptana Howto

Well yesterday, both Gentoo 2007.0 and Aptana milestone 8 were released. Thanks to some bugs in a previous release I was able to test milestone 8 on Gentoo last week; that was before ATI’s drivers went kamikaze.

Overall I am impressed with milestone 8, it features more advanced support of PHP, including variable highlighting. With Gentoo to install Aptana just make a folder in /usr/lib called aptana, then extract the archive to that point. After that make a file in /usr/bin called aptana, open it in your favorite editor (nano) and add the following:

#!/bin/sh
export MOZILLA_FIVE_HOME=/usr/lib/mozilla-firefox
exec /usr/lib/aptana/Aptana

Save the file and do a chmod 755 on it so that it becomes executable. Now try typing in the command aptana& into your terminal. If all goes right you should see the aptana splash screen. If you get a bug, look at the log file it directs you to. Should you see something like org.eclipse.swt.SWTError: No more handles [Unknown Mozilla path (MOZILLA_FIVE_HOME not set)] then your mozilla path is not correct. If the executable fails in general, you need to make sure you have the JRE 1.5 or newer. To get this just run emerge -p sun-jre-bin (you don’t have to use Sun’s JRE but that is what I use) if you like what you see then rerun the command without the -p. Once portage finishes doing its stuff, try executing Aptana again. It should work then, if not search the Aptana forums.

-John Havlik

[end of transmission, stay tuned]