LinkArray include category permalink

2 posts by 2 authors in: Forums > CMS Builder
Last Post: April 29, 2014   (RSS)

By Chris - April 29, 2014

Hi Jeremy,

Generating the _link field will require another call to getRecords(), whether you're using the standard _link (which is generated from other fields) or a permalink _link. A simple solution would be to replace your code with this:

<?php
$where = 'num IN (' . mysql_escapeCSV($record['category:values']) . ')';
list($linkRecords) = getRecords(array(
  'tableName'   => 'category', // TODO: set this to the tableName for your link records
  'where'       => $where,
  'allowSearch' => false,
));
foreach ($linkRecords as $linkRecord): ?>
<a href="<?php echo $linkRecord['_link']; ?>"><?php echo $linkRecord['title']; ?></a>,
<?php endforeach ?>

Does that work?

However, if your code is already inside of a foreach, this is going to mean an extra getRecords() call per $record you're displaying, which may slow down your page. Let me know if this is a problem and I can show you how to load all the child records all at once (caching them at the top of your page).

All the best,
Chris