How can I retrieve the SEF link of an article by its ID?
I think about a thing like this:
$link = get_link(34); // where 34 is the article ID
<a href="<?php echo $link; ?>">Article link</a>
UPDATE My code is this (updated with Rikesh code):
Mysql query: "SELECT id, title, extra_fields FROM xxxxx_k2_items WHERE catid = ".$catid
$n=0; //counter
while($row = mysql_fetch_array($result)){
$titles[$n] = $row['title'];
$links[$n] = JRoute::_(ContentHelperRoute::getArticleRoute($row['id'], $catid));
$n++;
}
Ok, now this retrieves links like /joomla/index.php/currentpage?id=4
where 4 is the correct id but the link doesn't work! It goes to a wrong page. My doubt is: your code works also for K2 articles? Because I'm working with K2 articles not default joomla articles. Edit: yes, I've checked my doubt, your code links to the Joomla articles by ID, but the IDs i'm using are for K2 articles!
Notice: I'd need of the SEF link