|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
ShamusMay Smarty Rookie
Joined: 28 Apr 2015 Posts: 18
|
Posted: Thu May 07, 2015 4:50 pm Post subject: Breadcrumb Help |
|
|
I'm using Smarty, PHP and MySQL. Need help creating the correct PHP/SQL function for passing a breadcrumb trail to the Smarty template.
Trying to achieve a multi-level breadcrumb like this...
Home > Parent > Child > Item
Here's my simple DB layout.
TABLE NAME : CATEGORY
Code: |
category_id category_name category_parent_id category_filename
1 Parent 0 index.html
2 Child 1 index2.html
3 Item 2 index3.html
|
Need a PHP function and Smarty code to display the breadcrumb.
Have been working on this for a week and am getting nowhere. Any help is GREATLY appreciated.
Current breadcrumb code only displays the current category you are in, but not it's parent.
Code: | <ul class="breadcrumb">
<li> <a href="/">Home</a> </li>
<li class="active">{$category_name} </li>
</ul> |
Last edited by ShamusMay on Fri May 08, 2015 4:24 pm; edited 2 times in total |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
|
Back to top |
|
ShamusMay Smarty Rookie
Joined: 28 Apr 2015 Posts: 18
|
Posted: Thu May 07, 2015 7:10 pm Post subject: |
|
|
OK...
I have the breadcrumb displaying the correct path, but the links are not clickable. I'm left with a link structure like this...
Home \ Cat1 \ Cat2
How can I make the parent category in the breadcrumb be linked? I have the filenames stored in the database, so I think it is possible.
Code: | function get_crumbs($the_id, $flarn, $keep_cat_id) {
$link_to_page=$_SERVER['PHP_SELF'];
if (!isset($the_id)) {
$the_id ="0";
echo "Home \ ";
}
$sql = "SELECT category_id, category_parent_id, category_name, category_filename from category ";
$sql .="where category_id = $the_id";
$show_crumb_trail = mysql_query($sql);
$num_crumbs = mysql_num_rows($show_crumb_trail);
if ($num_crumbs > 0) {
list($cat_id, $cat_parent, $cat_name) = mysql_fetch_row($show_crumb_trail);
$cat_id_array[$flarn] = $cat_id;
$cat_parent_id_array[$flarn] = $cat_parent;
$cat_name_array[$flarn] = $cat_name;
if ($cat_id_array[$flarn] > 0) {
mysql_free_result($show_crumb_trail);
$next = $flarn+1;
if ($flarn == 0 ) {
echo '<a href="/">Home</a> \ ';
}
get_crumbs($cat_parent_id_array[$flarn], $next, $keep_cat_id);
if ($keep_cat_id==$cat_id_array[$flarn]) {
echo $cat_name_array[$flarn];
} else {
echo "$cat_name_array[$flarn] \ ";
}
}
}
} |
Code in the template file... Probably not the right way to do it, so please correct me if there is a better way.
Code: |
{php} get_crumbs({$category_id}, "0", {$category_id}); {/php} |
|
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|