Modified breadcrumb

Post custom hacks and enhancements for phpwcms here only. Maybe some of these things will be included in official release later.
Post Reply
jamba
Posts: 50
Joined: Fri 23. Apr 2004, 11:18
Location: UK
Contact:

Modified breadcrumb

Post by jamba »

There's a minor flaw in the standard breadcrumb, which I've done my best to address. Basically, if you have a number of articles within a section and you are looking at one of these, there is no link back to the first article in the section (which I'll call the default article).

It's easier to explaing if you consider a structure like this...
Home
-- Section 1
-- Section 2
---- Article 1 ('default' in this section)
---- Article 2
---- Article 3
---- Article 4
If you look at the Article 1 page, your standard breadrumb would look like this (bold indicates a <a> link):
Home > Section 2 > Article 1
OK, that's cool. But when you click down 1 link further, say to Article 3, the breadcrumb does not change. This may be fine for many setups, but if like me your 'default' article in a section acts as a home page for the section in question, this may not be enough.

The amendment below will allow you to create the following breadcrumbs.

Example 1(looking at the 'default' article in the Section 2 section):
Home >
This indicates that the level above you is the Home page.

Example 2(looking at Article 3, in Section 2):
Home > Section 2 >
This indicates that you have drilled down from the home page, to Section 2, and then on down to Article 3.

The amendment to the code also adds a title attribute to each link tag, so in example 2 above, hovering over the Section 2 link would produce the following 'tooltip' in the same way as an alt attribute of an image would:
Back up to Section 2 page
This might not be what you're after for your own sites, but here's the amended code if you're interested...

Open /include/inc_front/front.func.inc.php and replace the following if/else block...

Code: Select all

if(sizeof($crumbs_part)) {
		$breadcrumb = "";
		foreach($crumbs_part as $key => $value) {	
			$alias = '';
			if ($act_id != $key) {
				if($breadcrumb) $breadcrumb .= $spacer;
				if(!$struct_array[$key]["acat_redirect"]) {
					$breadcrumb .= '<a href="index.php?';
					$alias = $struct_array[$key]["acat_alias"];
					$breadcrumb .= ($alias) ? html_specialchars($alias) : 'id='.$key.',0,0,1,0,0';
					$breadcrumb .= '">';
				} else {
					$redirect = get_redirect_link($struct_array[$key]["acat_redirect"], ' ', '');
					$breadcrumb .= '<a href="'.$redirect['link'].'"'.$redirect['target'].'>';
				}
				$breadcrumb .= html_specialchars($crumbs_part[$key]).'</a>';
			} else {
				if($breadcrumb) $breadcrumb .= $spacer;
				$breadcrumb .= html_specialchars($crumbs_part[$key]);

			}
		}
	} else {
		$breadcrumb = "";
	}
...with the following...

Code: Select all

if(sizeof($crumbs_part)) {
		$breadcrumb = "";
		foreach($crumbs_part as $key => $value) {	
			$alias = '';
			if ($act_id != $key) {
				if($breadcrumb) $breadcrumb .= $spacer;
				if(!$struct_array[$key]["acat_redirect"]) {
					$breadcrumb .= '<a href="index.php?';
					$alias = $struct_array[$key]["acat_alias"];
					$breadcrumb .= ($alias) ? html_specialchars($alias) : 'id='.$key.',0,0,1,0,0';
					// added a title attribute here that draws its content from the category name
					$breadcrumb .= '" title="Go back up to the '.html_specialchars($crumbs_part[$key]).' page">';
				} else {
					$redirect = get_redirect_link($struct_array[$key]["acat_redirect"], ' ', '');
					// added a title attribute here that draws its content from the category name
					$breadcrumb .= '<a href="'.$redirect['link'].'"'.$redirect['target'].' title="Go back up to the '.html_specialchars($crumbs_part[$key]).' page">';
				}
				$breadcrumb .= html_specialchars($crumbs_part[$key]).'</a>';
			} else {
				/* 	
					edited code here to check the number "." characters in the url
					this assumes that rewrite is turned on and you links look like this:
						13.7.0.0.0.0.shtml for an article
						aliasname.shtml for a section that has the alias 'aliasname'
					if rewrite is turned off and your links look like this:
						index.php?id=13,7,0,0,0,0 for an article
						index.php?aliasname for a section that has the alias 'aliasname'
					you'll need to uncomment the lines below 
				*/
					
				$querystring = $_SERVER['QUERY_STRING'];				// get qs value
				if($querystring != "index") $breadcrumb .= $spacer; 	// append spacer character if required
				// uncomment the line below this if you need to but remember to comment out the one below it too!
				// if(substr_count($querystring, ",") == 5) $breadcrumb .= '<a href="index.php?'.$struct_array[$key]["acat_alias"].'" title="Go back up to the '.html_specialchars($crumbs_part[$key]).' page">'.html_specialchars($crumbs_part[$key]).'</a>'.$spacer;
				if(substr_count($querystring, ".") == 5) $breadcrumb .= '<a href="'.$struct_array[$key]["acat_alias"].'.shtml" title="Go back up to the '.html_specialchars($crumbs_part[$key]).' page">'.html_specialchars($crumbs_part[$key]).'</a>'.$spacer;
			}
		}
	} else {
		$breadcrumb = "";
	}
One thing I should point out is the example above is working on an installation that has url rewrite turned on. You'll need to edit the code slightly if you have not edited your installation to support fully search-engine friendly URLs, as explained elsewhere in this forum:
aliasname.shtml translates to index.php?aliasname
13.6.0.0.1.0.shtml translates to index.php?id=13,6,0,0,1,0
Hope this helps somebody as much as it has me :D
Russ Back :D
Jamba Solutions
http://jambasolutions.com
cyrano
Posts: 1598
Joined: Sat 31. Jan 2004, 18:33
Location: Stuttgart
Contact:

UPDATE.

Post by cyrano »

hi i tried this with the newest release and had to change ".shtml" to ".phtml",than it works.

regards

UPDATE: I used your hack, works fine.

One question:

I have a structure called "Home" where I redirect to index.php.

I need this to have a home also in NAV_TABLE_COLUMN.

But when i open the URL and start with the index.php, then i get in my breadcrumb navigation a single ">".

How can I delete this or make it hidden?

Thank you for advice.

reagrds
Gruß/ regards cyrano
--------------------------------------------------------
templates -> http://www.128.weitzelmedia.de
planepix -> http://www.planepix.de
XING -> https://www.xing.com/profile/Thomas_Weitzel3
nbarraud
Posts: 7
Joined: Tue 8. Mar 2005, 14:01

Re: Modified breadcrumb

Post by nbarraud »

jamba wrote:If you look at the Article 1 page, your standard breadrumb would look like this (bold indicates a <a> link):
Home > Section 2 > Article 1
Hi,

Sorry to bring that old topic up to the top, but I can't figure out how you got the "standard breadrumb" to behave like this.
By creating 2 or more articles in a section and by going to the first article of that list, my breadcrumb shows :
Home > Section 2
and not, like you :
Home > Section 2 > Article 1
In one word, my article is not shown in my standard breadcrumb, as opposed to yours.
nbarraud
Posts: 7
Joined: Tue 8. Mar 2005, 14:01

Post by nbarraud »

up
Evoplure
Posts: 43
Joined: Fri 8. Jul 2005, 02:59

Post by Evoplure »

Hello!

I have tried the suggested code in 1.2.3-DEV, but unfortunately the link of the last section in the breadcrumb is just ".../index.php?", without the id identification number for that section.

I have checked different possibilities, but they didn't work. I noted that the first line in 1.2.3-DEV is:

Code: Select all

if(is_array($crumbs_part) && count($crumbs_part)) {
instead of

Code: Select all

if(sizeof($crumbs_part)) { 
I don't know if it's a relevant detail for my problem.

Url rewrite is off in my installation, so I work with the uncommented line. Maybe the problem is in that part of the code... I suppose so, but I am not an expert on PHP and this question has got me really disoriented.

Any help or suggestion is welcome, I really need this feature for my website.

Thank you
Post Reply