Link to Permalink.

By Toledoh - March 29, 2016

Hi all.

I have a section called Artists, and each record has a permalink, which works fine when I can use <?php echo $artistsRecord['permalink']; ?>

However, I'm listing records from "music" and I want to create a link to the artist associated with each item, so I currently use

// load records from 'events'
list($musicRecords, $musicMetaData) = getRecords(array(
'tableName' => 'music',
'loadUploads' => true,
'allowSearch' => false,
));

...

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

<a href="/artistDetail.php?num=<?php echo htmlencode($record['artist']) ?>">

....

How do I get the link to go to the permalink, rather than the php page?

Cheers,

Tim (toledoh.com.au)

By gregThomas - March 31, 2016

Hey Tim, 

I've done some local testing, and this should work:

<?php

  // load records from 'events'
  list($musicRecords, $musicMetaData) = getRecords(array(
  'tableName' => 'music',
  'loadUploads' => true,
  'allowSearch' => false,
  'leftJoin'    => array('artists' => 'artist'),
  ));

?>
<?php foreach ($musicRecords as $record): ?>
  <a href="<?php echo htmlencode($record['artists.permalink']) ?>"><?php echo htmlEncode($record['artists.title']); ?></a><br>
<?php endforeach; ?>

So the above code left joins to the artist table so that we have access to all of the artist fields.

Then you can cycle through  the music records and display the artist permalink by prefixing any artist field with artists. 

Cheers,

Greg

Greg Thomas







PHP Programmer - interactivetools.com