如何通过 ID 检索文章的SEF链接?
我想这样的事情:
$link = get_link(34); // where 34 is the article ID
<a href="<?php echo $link; ?>">Article link</a>
更新 我的代码是这样的(用 Rikesh 代码更新):
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++;
}
好的,现在这会检索像/joomla/index.php/currentpage?id=4
4 是正确 id 但链接不起作用的链接!它进入了错误的页面。我的疑问是:您的代码也适用于 K2 文章?因为我使用的是 K2 文章而不是默认的 joomla 文章。编辑:是的,我已经检查了我的疑问,您的代码按 ID 链接到 Joomla 文章,但我使用的 ID 用于 K2 文章!注意:我需要SEF链接