Question about GetlistLabels

6 posts by 2 authors in: Forums > CMS Builder
Last Post: January 20, 2020   (RSS)

By mbareara - January 1, 2020

I know that i can use <?php echo join('/ ', getListLabels('restaurants', 'cuisine', $restaurantsRecord['cuisine'])); ?> 

But, if i would have <a href="link1">label1</a>, <a href="link2">label2</a>, etc ?

thank you in advance for your help

Orazio

By mbareara - January 2, 2020 - edited: January 2, 2020

UPDATE

i found a solution on this forum...



<?php foreach ($restaurantsRecord['cuisine:labels'] as $tag ) : ?>

<?php echo $tag; ?><?php endforeach; ?>

THis is a good solution, but, what can i do if i would have a link for each tag with cuisine NUM ?

By mbareara - January 2, 2020

yesssss!!! great solution!

Hi Steve, it was very helpful for detailed page but it doesn.'t work on a list page.

Does it need some change on code?

Thank you in advance

Orazio 

By Steve99 - January 20, 2020

Glad it helped! Yes, there would be some changes needed for use on the list page.

You could loop through the restaurant records and query the cuisine records inside that loop. This could be made more elegant, and this hasn't been tested, but you can do something like this:

<?php
  // load records from 'restaurants'
  list($restaurantsRecords, $restaurantsMetaData) = getRecords(array(
    'tableName'   => 'restaurants',
    'loadUploads' => true,
    'allowSearch' => false,
  ));
?>

<?php foreach ($restaurantsRecords as $record): ?>

  Record Number: <?php echo htmlencode($record['num']) ?><br>
  Title: <?php echo htmlencode($record['title']) ?><br>
  _link : <a href="<?php echo $record['_link'] ?>"><?php echo $record['_link'] ?></a><br>  
  
  <?php
    // load records from 'yourCuisineTable'
    list($yourCuisineTableRecords, $yourCuisineTableMetaData) = getRecords(array(
      'tableName'   => 'yourCuisineTable',
      'where'       => '`num` IN('.mysql_escapeCSV($record['cuisine:values']).')',
      'loadUploads' => true,
      'allowSearch' => false,
    )); 
  ?>
  
  <?php foreach ($yourCuisineTableRecords as $record2): ?>
   Record Number: <?php echo htmlencode($record2['num']) ?><br>
   Title: <?php echo htmlencode($record2['title']) ?><br>
   _link : <a href="<?php echo $record2['_link'] ?>"><?php echo $record2['_link'] ?></a><br>  
  <?php endforeach ?>
  
<?php endforeach ?>

Best,
Steve