We hope you enjoy your visit.

You're currently viewing our forum as a guest. This means you are limited to certain areas of the board and there are some features you can't use. If you join our community, you'll be able to access member-only sections, and use many member-only features such as customizing your profile, sending personal messages, and voting in polls. Registration is simple, fast, and completely free.


Join our community!


If you're already a member please log in to your account to access all of our features:

Username:   Password:
Add Reply
PHP...breadtrail?; Dunno what it's called.
Topic Started: Jun 15 2005, 06:42 PM (984 Views)
JoeC
Euch! IE tastes horrible!
[ *  *  *  *  * ]
You know what I mean. You go on a site, and at the top, as you browse, a little navtrail creates itself (like at the top of this forum - "InvisionFree > Community Forums > Programming and Scripting Chat")

Just wondering how to write PHP to get that.

I've tried this:

Top of the page:
Code:
 
<php
$navtrail = "<a href=\"home.php\">Home</a>
?>

That bit works.

On a link (messy):
Code:
 
<a href="<?= $navtrail .= "<a href=\"#\">Page</a>"; ?page=newpage; ?>">A link</a>


Or, more neatly:
Code:
 
<a href="
<?=
$navtrail .= "<a href=\"#\">Page</a>";
?page=newpage;
?>
">A link</a>



But it don't work...and I can't think of how to make it work.

Can somebody kind please post the code for this and put me out of my misery?

Thanks. :)
Offline Profile Quote Post Goto Top
 
JCink
Member
[ *  *  *  *  * ]
I do it on here:
http://jcinkcom.ho8.com/php/sources/admin/...&topicname=tdst

But it's controled by GET. My way of displaying it on that page there is extremely messy:

Code:
 
<div align=left>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href=index.php><?php echo "$forum_name"; ?></a> » <a href='topicdisplay.php?forum=<?php echo "$forum"; ?>&show=<?php echo "$show"; ?>'><?php if ($forum) { echo "$forum"; } ?></a> » <a href='viewtopic.php?topicid=<?php echo "$topicid"; ?>&forum=<?php echo "$forum"; ?>&topicname=<?php echo "$topicname"; ?>'><B>Viewing Topic</b></a></div>
<br>
<div class='tableborder'><table width=100%% cellpadding='4' cellspacing='1'><td width=15%% align=center class=headertableblock>User Info</td><td width=60%% align=center class=headertableblock>Viewing Topic: <?php echo "$topicid"; ?></td><tr>


But it does work. I dont know how your site is structured so I dont know if this is of any use...
Offline Profile Quote Post Goto Top
 
JoeC
Euch! IE tastes horrible!
[ *  *  *  *  * ]
It's like that I suppose...I'm oding a shop (however long it takes me :P) so it goes Index -> Category -> Subcategory -> Item.

I'll dis-assemble that code in the morning, and if anyone has any simpler ideas, please post those too.

Thanks :)

And if anyone can tell me what it's called (I know I heard a name for it with 'bread' in the title), I'd appreciate that too
Offline Profile Quote Post Goto Top
 
Sani
Member Avatar
Member
[ *  *  *  *  * ]
Maybe you can use this as a base..

Code:
 
$navtrail = "<a href=\"home.php\">Home</a>
echo "".$navtrail." > <a href=\"?page".$id."\">Test</a>";


Say the link is http://mysite.org/?page=spam
The code will show..

Code:
 
Home > Test


With "Home" pointing to home.php and "Test" pointing to ?page=spam

:)

Edit: Forgot the slashes.. Slashes are evil..
Offline Profile Quote Post Goto Top
 
Seth
Member Avatar
I has a pony
[ *  *  *  *  *  *  *  *  * ]
Oh people. If you want a trail, do it programmatically.
Code:
 
<?php
$trail[0] = '<a href="#">Home</a>';
$trail[1] = '<a href="#">Shop</a>';
$trail[2] = '<a href="#">Buy Item</a>';

foreach ($trail as $idx => $item)
{
if ($idx < count($trail) - 1) {
echo($item . ' &raquo; ');
}
}

echo($trail[$idx]);
?>
Offline Profile Quote Post Goto Top
 
JoeC
Euch! IE tastes horrible!
[ *  *  *  *  * ]
OK Seth, thanks for that, I've wrapped it into a function, and just wondering how I can have the trail set as 0 (for Home), and when a link is clicked, have it update. I'm using hyperlinks of ?act=example rather than pages.
Offline Profile Quote Post Goto Top
 
JoeC
Euch! IE tastes horrible!
[ *  *  *  *  * ]
Seth? Please can you post the PHP for updating the trail without the page actually reloading (IF it's possible). If not, then how would you suggest I implement the trail when using .. a template, for lack of a better word.
Offline Profile Quote Post Goto Top
 
FearKiller
Member Avatar
www.drewscripts.com
[ *  *  *  *  * ]
Code:
 
<?php
// CREATED BY SETH KINAST
$trail[0] = '<a href="#">'. $_GET['act'] .'</a>';
$trail[1] = '<a href="#">Shop</a>';
$trail[2] = '<a href="#">Buy Item</a>';

$trailcount = count($trail);

foreach ($trail as $idx => $item)
{
if ($idx < $trailcount - 1) {
echo($item . ' &raquo; ');
}
}

echo($trail[$idx]);
?>

I editted Seth's code. $trail[0] will now update based on what the "act" get variable is assigned to. I've also removed the count() function from the loop and placed it as a variable for performance purposes. No need for PHP to count $trail more than once.

Is that what you wanted?
Offline Profile Quote Post Goto Top
 
JoeC
Euch! IE tastes horrible!
[ *  *  *  *  * ]
I've modded that script to make it nicer :)

Code:
 

//CREATED BY SETH KINAST, Modded by FearKiller and JC
<?php
function breadtrail() {
$trail[0] = '<a href="#">Home</a> ';
if ($_GET['cat'] != "") {
$trail[1] = ' &raquo; <a href="#">' . $_GET['cat'] . '</a> ';
if ($_GET['idx'] != "") {
 $trail[2] = ' &raquo; <a href="#">' . $_GET['idx'] . '</a>';
 if ($_GET['item'] != "") {
  $trail[3] = ' &raquo; <a href="#">' . $_GET['item'] . '</a>';
  if ($_GET['act'] != "") {
   $trail[4] = ' &raquo; <a href="#">' . $_GET['act'] . '</a>';
  }
 }
}
}

$trailcount = count($trail);

foreach ($trail as $idx => $item)
{
if ($idx < $trailcount - 1) {
echo($item);
}
}
echo($trail[$idx]);
}
?>


Much better ^.^
Offline Profile Quote Post Goto Top
 
James
Member Avatar
Live to Dream
[ *  *  *  *  *  *  * ]
Hmm, that top bit doesnt' look very neat. Can't you have 'cat', 'idx', 'item' and 'act' in an array, then run through each and check if the $_GET[ array[x] ] != "" and added it to the trail

In JS, it'd look something like:

Code:
 

var arr = [ 'cat' , 'idx' , 'item', 'act' ];
var trail = '';

for(i=0;i<arr.length;i++){
if($_GET[ arr[i] ] != ""){
   trail += ' &raquo; <a href="#">' + $_GET['cat'] + '</a> ';
 }
}

..write(trail)


Or am i being too simple about it? Just seems like you're going to have a lot of if statements if that trail extends further.
Offline Profile Quote Post Goto Top
 
JoeC
Euch! IE tastes horrible!
[ *  *  *  *  * ]
:arr:

Sorry, the code for that is : arr:

I just like the fact you use a var called "arr" :)

ONtopic, I tried converting it to PHP, and ended up with

Code:
 
$arr = array ("cat", "idx", "item", "act");
$trail = "";

for($i=0;$i<$arr.length;$i++)
{
if(isset($_GET[$arr]))
{
   $trail .= " &raquo; <a href="#">" . $_GET['cat'] . "</a>";
}
}


But it doesn't work...tried to fix it. Any ideas?
Offline Profile Quote Post Goto Top
 
James
Member Avatar
Live to Dream
[ *  *  *  *  *  *  * ]
Don't you have to use $arr?

I'm really not a PHPer at all, i'm just doing this through guesswork and the similarity of JS.

and:

........href="#">" . $_GET['cat'] . "</a>";

would be:

.........href="#">" . $_GET[ $arr ] . "</a>";

?
Offline Profile Quote Post Goto Top
 
Jory
Member Avatar
Member
[ *  *  *  *  *  * ]
$_GET[ $arr[$i] ]
You mean :)

And does arr.length work in PHP?
Shouldn't you do count($arr)

Code:
 

$arr = array ("cat", "idx", "item", "act");
$trail = "";
$arr_length = count($arr);
for($i=0;$i<$arr_length;$i++)
{
if(isset($_GET[$arr]))
{
  $trail .= " &raquo; <a href="#">" . $_GET[ $arr[$i] ] . "</a>";
}
}


Think this would do it.
Offline Profile Quote Post Goto Top
 
1 user reading this topic (1 Guest and 0 Anonymous)
« Previous Topic · Technology Chat · Next Topic »
Add Reply