php - Joomla K2 - Get article link (SEF) by ID -
how can retrieve sef link of article id?
i think thing this:
$link = get_link(34); // 34 article id <a href="<?php echo $link; ?>">article link</a>
update code (updated rikesh code):
mysql query: "select id, title, extra_fields xxxxx_k2_items 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, retrieves links /joomla/index.php/currentpage?id=4
4 correct id link doesn't work! goes wrong page. doubt is: code works k2 articles? because i'm working k2 articles not default joomla articles. edit: yes, i've checked doubt, code links joomla articles id, ids i'm using k2 articles! notice: i'd need of sef link
you should include k2 route
require_once(jpath_site.ds.'components'.ds.'com_k2'.ds.'helpers'.ds.'route.php');
and should update both mysql query , php code because need info k2 categories table, here example
$db = jfactory::getdbo(); $query = ' select a.id id, a.extra_fields extrafields, a.catid catid, a.title title, a.introtext introtext, a.alias alias, c.alias catalias #__k2_items left join #__k2_categories c on ( a.catid = c.id ) a.published = 1 , a.catid = '.$catid; $db->setquery($query); $articles = $db->loadobjectlist(); $n=0; foreach ($articles $article) { $titles[$n] = $article->title; $links[$n] = k2helperroute::getitemroute($article->id.':'.urlencode($article->alias),$article->catid.':'.urlencode($article->catalias)); $n++; }
Comments
Post a Comment