|
As you have noticed the URLs to the various articles on your site are produced by Joomla dynamically. There is not a simple way to determine an article’s URL by the article’s title or id and at the end of the day; this is what we are looking for. To add to this, with SEO concepts and add-ons implementing them, not all Joomla installations construct URLs under the same principle. But of course, we are not the first with this kind of problem, Joomla has a helper function for this that resides in: /var/www/joomla/components/com_content/helpers/route.php to use it, at the beginning of our code we will place the following: require_once(JPATH_SITE.DS.'components'.DS.'com_content'.DS. 'helpers'.DS.'route.php'); Not to puzzle you, the DS thing, is the directory separator that depends on which OS you are running, this slash or the other slash? Have a look at the ContentHelperRoute class and see the getArticleRoute method, it does what we need. Test it before you use it. For a specific article on your site get the article id, the category id and the section id. To get these you have to access the article, category and section managers from the backend or query the jos_content table with phpmyadmin. The following should work: <?php require_once(JPATH_SITE.DS.'components'.DS.'com_content'.DS. 'helpers'.DS.'route.php'); $route = new ContentHelperRoute(); $link = $route->getArticleRoute(14,8,3); echo "<p><a href=\"" . $link . "\">A Great Article</a></p>"; ?> Good stuff, we can happily create links now. Just to mention here that the examples I‘ve seen so far, pass the link from the JRoute::_ method that translates the internal Joomla URL to a custom URL. I don’t think we need it here, this is SEF related. You may also visit this link to read more on routing. |