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

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

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: [chris] Breadcrumb Trail for Category Section Editor

Hi Chris, Yes that helps and got it working (sort of).

Top level page - works fine:

http://turnerhopkins.theclicklab.com/areas-of-practice-5/
Home > Areas of Practice

Second level page - missing top level item:

http://turnerhopkins.theclicklab.com/commercial-property-6/
should be Home > Areas of Practice > Commercial Property instead of Home > Commercial Property

Also, this second level page has the following error:

http://turnerhopkins.theclicklab.com/debt-recovery-16/
Notice: Undefined index: 1 in /home/turnerhopk/turnerhopkins.co.nz/page.php on line 71

Have attached the php file so you can see the code starting on line 55

Any suggestions?

Many thanks,
Jan
Attachments:

page_003.php 11K

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: [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/