Hi all,
I'm using Joomla 1.5
I just wondering how can I create a link to article link this -> index.php?view=article&catid=10&id=20&option=com_content&Itemid=30
if I know only id of article (in this example it's =20)
I try to write code like this
link
but It's not use the template that I assign for that article.. it's only work if I add more parameter, the Itemid=30 to it.. but It's cannot hard-code.. it's depend..
so.. are there any API or how to make a link if I know only article id?
Thank you very much,
ps. I can't query database to find it.. because It will be very slow since on that page I want to show a lot of articles..
How to get URL to article from ID?
Moderators: tjay, seadap, Rogue4ngel, matthewhayashida
Forum rules
How to get URL to article from ID?
Last edited by ShiRaTo on Mon Nov 26, 2007 4:39 pm, edited 1 time in total.
Re: How to get URL to article from ID?
now my problem is solved by this.
explain: I query DB for all article I have to get category ID list... when I want to show I call ContentHelperRoute::getArticleRoute and send article id with category id...
I'm not sure this's the best way or not.. but I use 1.5RC3 and I can't find how to do this...
I've read JApplication class that says "Deprecated, use ContentHelper::getItemid instead." but I think that'll query db everytime? or not? I can't find that source code in google or search forums here
Code: Select all
include dirname(__FILE__).'/../../components/com_content/helpers/route.php';
// Search Joomla to get Category ID of each article.
$db = &JFactory::getDBO();
$idList = "";
foreach ($resArticle->docs as $no => $doc) {
$idList .= $doc->sums["cityguidearticleid"].",";
}
$idList = substr($idList, 0, -1);
$db->setQuery('SELECT id,catid FROM #__content WHERE id in ('.$idList.')');
$rows = $db->loadObjectList();
foreach ( $rows as $row ) {
$articleLink[$row->id] = $row->catid;
}
and when I want to show..
<a href="<?php echo ContentHelperRoute::getArticleRoute($articleId, $articleLink[$articleId]); ?>">Article <?php echo $articleId; ?></a>
explain: I query DB for all article I have to get category ID list... when I want to show I call ContentHelperRoute::getArticleRoute and send article id with category id...
I'm not sure this's the best way or not.. but I use 1.5RC3 and I can't find how to do this...
I've read JApplication class that says "Deprecated, use ContentHelper::getItemid instead." but I think that'll query db everytime? or not? I can't find that source code in google or search forums here