如何通过文章的ID检索文章的链接?
我想到了这样的事情:
$link = get_link(34); // where 34 is the article ID
<a href="<?php echo $link; ?>">Article link</a>UPDATE我的代码如下(用代码更新):
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文章。编辑:是的,我检查了我的疑问,您的代码链接到Joomla文章的ID,但我使用的ID是K2文章!注意:我需要链接
发布于 2013-05-26 10:55:55
您应该包括K2路由
require_once(JPATH_SITE.DS.'components'.DS.'com_k2'.DS.'helpers'.DS.'route.php');您应该同时更新mysql查询和PHP代码,因为您还需要来自k2类别表的信息,下面是一个示例
$db = JFactory::getDBO();
$query = '
SELECT
a.id AS id,
a.extra_fields AS extrafields,
a.catid AS catid,
a.title AS title,
a.introtext AS introtext,
a.alias AS alias,
c.alias AS catalias
FROM
#__k2_items AS a
LEFT JOIN #__k2_categories AS c ON ( a.catid = c.id )
WHERE a.published = 1 AND a.catid = '.$catid;
$db->setQuery($query);
$articles = $db->loadObjectList();
$n=0;
foreach ($articles as $article) {
$titles[$n] = $article->title;
$links[$n] = K2HelperRoute::getItemRoute($article->id.':'.urlencode($article->alias),$article->catid.':'.urlencode($article->catalias));
$n++;
}https://stackoverflow.com/questions/16666169
复制相似问题