I'm having trouble using another article link in my "slideshow". In the article in Joomla it's possible to add 3 links, Link A, Link B and Link C. I'm sure it's is possible to use theese links with the PHP, but I really can't find out how.
At the moment, each article in the slideshow, is linking to itself. It looks like this:
<a target="_<?php echo $openTarget ;?>" title="<?php echo $row->title;?>" href="<?php echo $row->link;?>"><?php echo $row->title;?></a>
And I have tried to change the link, to linkA
<?php foreach ($articles as $key=>$article):
$articleImage = json_decode($article->images);
$articleLinks = json_decode($article->urls);
$link = NULL;
switch ($linkTo) {
case 'urlta':
$link = $article->link;
break;
case 'urla':
$link = $articleLinks->urla;
break;
case 'urlb':
$link = $articleLinks->urlb;
break;
case 'urlc':
$link = $articleLinks->urlc;
break;
case 'unurl':
$link = null;
break;
}
?>
Can anyone figure this out?
Your starting point was correct, the only thing you missed is the variable $linkTo. I can't see that is set in you quote.
if you simple want always to use "Link A" as target url for your slideshow you could use this code:
<?php
foreach ($articles as $key=>$article):
$articleLinks = json_decode($article->urls);
$link = $articleLinks->urla;
?>
<a title="<?php echo $article->title;?>" href="<?php echo $link;?>"><?php echo $article->title;?></a>
<?php
endforeach;
?>
If you like to use "Link A" only if it is set you could check if it exists:
<?php
foreach ($articles as $key=>$article):
$articleLinks = json_decode($article->urls);
$link = ($articleLinks->urla ? $articleLinks->urla : $article->link);
?>
<a title="<?php echo $article->title;?>" href="<?php echo $link;?>"><?php echo $article->title;?></a>
<?php
endforeach;
?>
<?php
$db =& JFactory::getDBO();
$query = "SELECT * FROM #__content WHERE id = ART-ID";
$db->setQuery($query);
$row = $db->loadAssoc();
$urls = json_decode($row['urls']);
?>
<?php echo $urls->{'urla'}; ?>
ART-ID
is the id of the article you are trying to get the URL from.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.