Forum Moderators: coopster

Message Too Old, No Replies

Using PHP in navigation crumb

Need a little guidance ...

         

andy_boyd

1:38 pm on Nov 2, 2005 (gmt 0)

10+ Year Member



Hi,

I'm pretty new to the world of PHP and need a little assistance. I've got a static site at the moment, but I'd like to make it a little easier to maintain and update.

One of the areas I think PHP will really help is with the navigation crumb. Rather than typing in all the information such as 'Home > Category > Article' ... what could I use?

I'd like PHP to just insert the Home URL, followed by the category name and URL, follwed by the article title.

Any help would be great. :)

lobo235

2:08 pm on Nov 2, 2005 (gmt 0)

10+ Year Member



This is not too hard to do if you save all your articles in a database. Save them with the category name/category url and then you can write a simple function that will create crumbs for any article. For example:


<?php
function createCrumb( $catname, $caturl, $artname, $arturl ) {
echo "<a href=\"/\">Home</a> &gt; ";
echo "<a href=\"$caturl\">";
echo "$catname</a> &gt; ";
echo "<a href=\"$arturl\">";
echo "$artname</a>";
}
createCrumb( "bob", "/bob_category.html", "Fish", "/articles/fish_article.html" );
?>

andy_boyd

2:33 pm on Nov 2, 2005 (gmt 0)

10+ Year Member



Thanks for that lobo ... the problem is that the pages are not in a database so that technique wouldn't work. Is there another workaround?

lobo235

2:48 pm on Nov 2, 2005 (gmt 0)

10+ Year Member



You could still use the function that I provided but you would have to provide the values for it manually. The advantage of having a database would be that you could feed the values to the function automatically.

technossomy

10:54 pm on Nov 7, 2005 (gmt 0)

10+ Year Member



andy_boyd

If this is of any relevance to your situation: it is one of the reasons that CMS's have become popular. Most CMS's run on PHP scripts and offer bread crumbs as part of their Open Source license.

Hope this helps

Tech