How to get URL to article from ID?

Discussion and education for beginner / novice programmers interested in embarking on the development process to take advantage of the extensible nature of the Joomla! CMS.

Moderators: tjay, seadap, Rogue4ngel, matthewhayashida

Forum rules
Post Reply
ShiRaTo
Joomla! Fledgling
Joomla! Fledgling
Posts: 2
Joined: Fri Sep 21, 2007 9:58 am

How to get URL to article from ID?

Post by ShiRaTo » Mon Nov 26, 2007 4:37 pm

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..
Last edited by ShiRaTo on Mon Nov 26, 2007 4:39 pm, edited 1 time in total.

ShiRaTo
Joomla! Fledgling
Joomla! Fledgling
Posts: 2
Joined: Fri Sep 21, 2007 9:58 am

Re: How to get URL to article from ID?

Post by ShiRaTo » Fri Nov 30, 2007 1:27 pm

now my problem is solved by this.


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


Post Reply