Building a breadcrumb trail

Hi all,

I currently have url structure as such:

http://www.mysitename.com/browse.php?cat_name=dresses&size=6&prod_brand=debenhams

How can I convert it into something like:

http://www.mysitename.com/browse.php/dresses/6/debenhams

so that I can build a breadcrumb trail (my breadcrumb trail script breaks a url into sections at “/”)

Thanks a lot in advance

I use Baskettcase’s script for breadcrumbs. You will probably need to use modrewrite to do the conversion. May want to post in the apache config forum here.

Before you post, check out: http://datakoncepts.com/seo
This is in dklynn’s sig, one of the main helpers in apache config, he will probably tell you to read that first.

After getting your url’s rewrote, check out the script I use, it is pretty easy, but I am not sure how it acts with dynamic urls.

froggie,

WHAT? You will need to turn on MultiViews to include the file in the path like that - IMHO, a very ugly URL! You could leave out the browse.php in the link YOU create and redirect to the original link easily but, as rg84 said, you’ve GOT to give it a try first.

Regards,

DK

Thanks guys, I’ll give it a go.


$_SESSION['history']['Page Title'] = $url;
while(count($_SESSION['history']) > 3) array_shift($_SESSION['history']);

This should do it basically, keeps the last 3 unique page titles seen in the session with the user clearly the html would be as follows


<ul>
<?php foreach($_SESSION['history'] as $title => $url): ?>
<li><a href="<?=$url?>"><?=$title?></a></li>
<?php endforeach; ?>

Thanks for this but it doesn’t seem to work so far - the only thing I’m seeing on all my pages is ‘Page Title’ just written like this.

If I roll over it, I can see that the url it’s pointing to is that of the page I’m currently on. How can I change it from saying ‘Page Title’ to the actual titles? And then make a breadcrumb trail out of them?

Thanks again

$_SESSION['history']['Page Title'] = $url; 

Change where it says ‘Page Title’ to be the title of the page.

Thank you, got that bit working. The only problem now is that it only displays one title per page (i.e. the title of the page you’re on), not the last three pages… Am I doing something wrong?

do a
print_r($_SESSION[‘history’]);

how many results does it show?

And you got sessions turned on correct?

It returned 1 result:

Array ( [Page title] => )

I’m not sure if I have sessions turned out - how do I find out? And if sessions are off, how do I turn them on?

turned on isn’t the best wording. You need to start/invoke a session


<?php session_start();?>

at the top of every page

at the beginning of every page use
session_start();
http://us3.php.net/session_start

that should fix this problem, thought you need to make sure $url contains the url of the page you’re viewing.

Thanks guys. I keep getting this warning - even thought the session function comes first, before everything else on the page:
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent

It only gives me this warning on the home page (although all my pages are using the same header). Any idea what could be happening?

Can you post what you have upto and including the line where you use session_start()

I don’t have anything up to the session start line, it is the first line of my header document. The header is included in all pages on my site.

So it looks as such from the top:

<?session_start();?>
<!doctype html>
<html lang=“en” class=“no-js”>
<head>

etc…

Is there any white space before the <? ?
Because that will cause it to fail.

Same thing with the pages that are including this file - there must be no un-PHP-encapsed whitespace before the include. The “<?php” before the include must be the first line, first character.

Thank you - that did it. My index page had a space before the header include, which is what was causing the problem.

Now the only problem I have is that the $url is always the same - i.e it only shows the url of the current page, regardless of which page title you click on or roll over. Any idea why?

Also, I’m giving mod rewrite a go - I’ve got the following in my htaccess file:

Options +FollowSymlinks
RewriteEngine on

RewriteRule ^browse/(\w+)/(\w+)/$ /browse.php?cat_name=$1&prod_brand=$2 [nc]

I want to turn http://www.mysite.com/browse.php?cat_name=dresses&prod_brand=debenhams

into http://www.mysite.com/browse/dresses/debenhams

So far the code in the htaccess file hasn’t worked, am I doing something wrong? my mod rewrite is definitely enabled and working properly, I’ve tested it.

Would you like us to move this thread to the Apache Configuration forum where mod_rewrite is handled?

OK so I used mod-rewrite to convert a url (so far just one to test), it looks like this:

browse/$cat_name/$prod_brand

Then I used the following script that rguy84 recommended: http://www.baskettcase.com/classes/breadcrumb/

I get the following breadcrumb trail: home>browse.php and that’s it, no $cat_name or $prod_brand shows up. What am I doing wrong?