Breadcrumb Trail for Category Section Editor

10 posts by 4 authors in: Forums > CMS Builder
Last Post: April 4, 2011   (RSS)

By theclicklab - August 20, 2010

Hi there,

Just looking for some instructions on how to implement a breadcrumb trail for a category section editor.

Have done some digging and have not found anything yet.

Many Thanks

Re: [aquaman] Breadcrumb Trail for Category Section Editor

By Chris - August 20, 2010

Hi aquaman,

There's a 'breadcrumb' field for category records which might be useful to you.

If you need something more involved, you can use the 'lineage' and/or 'parentNum' fields to identify which records should be in your breadcrumb trail.

If you can explain exactly what it is you want to accomplish, I can give you some sample code. :)

I hope this helps. Please let me know if you have any questions.
All the best,
Chris

Re: [chris] Breadcrumb Trail for Category Section Editor

By theclicklab - August 20, 2010

Hi Chris, Sample code would be great thanks :)

I have a category section setup for my pages. See attached screenshot of setup.

Breadcrumb code would be like so:

<a href="/">Home</a> <span>&rsaquo;</span> <a href="top-level-link">Top Level Name</a> <span>&rsaquo;</span> Second Level Name

cheers
Attachments:

pages.jpg 79K

Re: [aquaman] Breadcrumb Trail for Category Section Editor

By Chris - August 23, 2010 - edited: August 23, 2010

Hi aquaman,

The following PHP would generate breadcrumb HTML as you've provided above:

<?php
$categoriesRecordsByNum = array_combine(array_pluck($categoriesRecords, "num"), $categoriesRecords);

$lineage = explode("\t", trim(preg_replace("/:/", "\t", $selectedCategory['lineage'])));

$parents = array();
foreach ($lineage as $parentCatNum) {
$parents[] = $categoriesRecordsByNum[$parentCatNum];
}
?>

<a href="/">Home</a>
<?php foreach($parents as $parent): ?>
<span>&rsaquo;</span>
<?php if ($parent === $selectedCategory): ?>
<?php echo $parent['name'] ?>
<?php else: ?>
<a href="<?php echo $parent['_link'] ?>"><?php echo $parent['name'] ?></a>
<?php endif ?>
<?php endforeach ?>


This code assumes that your variables are called $categoriesRecords and $selectedCategory (highlighted in red above.) If they're not, you can change the variables in red to match your variable names.

Does this help? Please let me know if you have any questions.
All the best,
Chris

Re: [aquaman] Breadcrumb Trail for Category Section Editor

By Chris - August 23, 2010

Hi Jan,

The code I wrote requires $selectedCategory to be a fully-fledged record, not a record num. Also, since the code tests for equality, it'll need to be from the same record set as the results from getCategories().

Change the following code in red:

<?php
// load records for breadcrumb
list($pagesRecords, $selectedCategory) = getCategories(array(
'tableName' => 'pages',
'selectedCategoryNum' => '', // defaults to getNumberFromEndOfUrl()
'debugSql' => 'true',
));
?>
<?php
$selectedCategory=$pagesRecord['num'];


Does that help? Please let me know if you have any questions.
All the best,
Chris

Re: [Chris] Breadcrumb Trail for Category Section Editor

By terryally - April 1, 2011

Hi Chris,

I do not fully understand this i.e. the $categoriesRecords and $selectedCategory variables.

Are you saying that if I had a section editor named "Education" it would be my category and my variable would become $educationRecords?

Then the variable name for $selectedCategory would be $education?

Terry


<?php
$categoriesRecordsByNum = array_combine(array_pluck($categoriesRecords, "num"), $categoriesRecords);

$lineage = explode("\t", trim(preg_replace("/:/", "\t", $selectedCategory['lineage'])));

$parents = array();
foreach ($lineage as $parentCatNum) {
$parents[] = $categoriesRecordsByNum[$parentCatNum];
}
?>

<a href="/">Home</a>
<?php foreach($parents as $parent): ?>
<span>&rsaquo;</span>
<?php if ($parent === $selectedCategory): ?>
<?php echo $parent['name'] ?>
<?php else: ?>
<a href="<?php echo $parent['_link'] ?>"><?php echo $parent['name'] ?></a>
<?php endif ?>
<?php endforeach ?>


This code assumes that your variables are called $categoriesRecords and $selectedCategory (highlighted in red above.) If they're not, you can change the variables in red to match your variable names.


Re: [terryally] Breadcrumb Trail for Category Section Editor

By Jason - April 1, 2011

Hi Terry,

The variables $categoriesRecords and $selectedCategory are the two variables you get as a result of using the getCategories Function.

For example:

list($categoriesRecords, $selectedCategory) = getCategories(array(
'tableName' => 'my_categories'
));


In this example, "my_categories" would be the name of my section. The code you're showing will only work if the section you're using is a category section.

Hope this helps clarify. Please let me know if you have any other questions.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Breadcrumb Trail for Category Section Editor

By terryally - April 1, 2011 - edited: April 3, 2011

Hi Jason,

I sorta understand, me thinks.

In Section Editors, instead of choosing "single record" or "multi record" I can instead select "category menu" which I can use in a similar fashion as a "multi record" with the added benefit of breadcrumbs??

Thanks.

Terry

Re: [terryally] Breadcrumb Trail for Category Section Editor

By Jason - April 4, 2011

Hi Terry,

Glad that helped. Please let us know if you have any other questions.

Thanks
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/