Link to Permalink.
3 posts by 2 authors in: Forums > CMS Builder: Plugins & Add-ons
Last Post: March 31, 2016 (RSS)
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?
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
PHP Programmer - interactivetools.com
By Toledoh - March 31, 2016
Great! I've added a leading forward slash to bring it back the the base.
Thanks!
Tim (toledoh.com.au)