Category List Control

6 posts by 2 authors in: Forums > CMS Builder
Last Post: February 25, 2010   (RSS)

Here's a quickie, gang.

I'm starting to make good use of the list category controls - in particular the '_isSelectedBranch' and '_isSelected' queries.

However, what is the simplest/most efficient method to ask if a record 'has a Parent' or 'has a Child'

:0)

Perchpole

Re: [Dave] Category List Control

Hi, Dave -

I'm exploring ways to move between related categories. Specifically, I'd like the system to display links to child and parent categories if they exist.

In coding terms I want to say: "if this category/page has a child, create a link to it..."

A similar statement would be used to identify the existence of a parent.

This would be an incredibly neat and useful way of linking a chain of pages together. All you need to do is make each successive page a child of the previous page. You should then be able to move up and down the chain in a prescribed sequence.

Think of it as a kind of inter-category pagination!

I've already used this set-up on a site I'm developing for a client. There was too much text to display on his "About Us" page so it had to be spread across multiple pages. At the foot of each page the system displays a "more..." link which takes the reader to the next descendent in the order.

The only drawback is the code - which is rather clunky! In effect you have to pull up the entire category network, then exclude every link that doesn't apply by means of <if... {continue}> rules. What's left is usually a link to the previous or next page!

I just think it would be really useful if we could do this by means of a single piece of code. Clients would then be better able to add/insert pages wherever a specific sequence is required, complete with the necessary links.

Must be worth further investigation.

:0)

Perch

Re: [Perchpole] Category List Control

By Dave - February 25, 2010

Hi Perch,

If I added fields for: _hasParent and _hasChild would that work? _hasParent would be the same as !$record['parent'] though since only root nodes wouldn't have parents, but it would be more readable.

Also, check out this function in /lib/viewer_functions.php for moving between records:

// Supported options: tableName (required), recordNum (optional), and
// ... orderBy (optional, defaults to schema listPageOrder)
list($prevRecord, $nextRecord, $firstRecord, $lastRecord) = getPrevAndNextRecords(array(
'tableName' => 'news',
'recordNum' => $record['num'],
'orderBy' => 'createdDate', // optional - defaults to schema listPageOrder
));

Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Category List Control

Hi, Dave -

Sounds perfect. You've suggested exactly what I was hoping for!

Thanks (again!)

:0)

Perch

Re: [Perchpole] Category List Control

By Dave - February 25, 2010

Try this to add _hasChild and _hasParent:

- Open /lib/viewer_functions.php
- Search for: remove categories
- Add the code in red _above_ that line:
// get array of category nums with children
$categoryNumHasChildren = array();
foreach ($categoryRecords as $record) { $categoryNumHasChildren[ $record['parentNum'] ] = 1; }

// remove categories we aren't displaying


- Then search for: _isBreadcrumb
- And add the code in red _below_ that line:
$category['_isBreadcrumb'] = $category['_isDescendantSelected'] || $category['_isSelected'];

$category['_hasParent'] = (int) ($category['parentNum'] != 0);
$category['_hasChild'] = (int) @$categoryNumHasChildren[ $category['num'] ];


Hope that helps! Let me know if that works for you.
Dave Edis - Senior Developer
interactivetools.com