Happpi PHP Library

getCategoryBreadCrumbs()

Returns the categories and subcategories in which it took to get to this category.

Return Type

Array of type: CurtCategory

Required Parameters

    None

Optional Parameters

    None

Dependencies

    $category->setCatID(int $value)

Example:


<!-- getCategoryBreadCrumbs() -->
<?php
	require_once('libraries/happpi/LoadAll.php'); // points to the LoadAll.php file for loading the library.

	// once the library is required, you can now use one of the main "interaction" classes.
	// These interaction classes contain methods that get information from our REST API and
	// converts them to PHP objects for you to use.
	$Category = new CurtCategory(); // create a new category object to gain access to its functions.
	$Category->setCatID(7); // set the required dependency of CatID to select which category the bread crumbs are for.

	echo "<h2>BreadCrumbs for a Category</h2>";
	$numItems = count($Category->getCategoryBreadcrumbs()); // get the number of bread crumb items.
	$i = 0; 
	foreach($Category->getCategoryBreadcrumbs() as $catBreadCrumb){ // step through each breadcrumb
		$i += 1;
		if($numItems == 1){ // if there is only one breadcrumb, dont display an arrow seperator after the link.
			echo '<a href="category.php?catID=' . $catBreadCrumb->getCatID() . '">';
			echo $catBreadCrumb->getCatTitle();
			echo "</a>";
		}elseif($numItems > 1 && $i != $numItems){ // if its not the first or last breadcrumb, display the breadcrumb title and arrow seperator.
			echo '<a href="category.php?catID=' . $catBreadCrumb->getCatID() . '">';			
			echo $catBreadCrumb->getCatTitle();
			echo "</a>";
			echo " > ";
		}else if($i == $numItems){ // if it is the last breadcrumb item, just display the name.
			echo $catBreadCrumb->getCatTitle();
		}
		
	} // end of foreach

?>