Reputation: 10525
I have the following code for joomla 2.5 ....
<?php
$app = JFactory::getApplication();
$menu = $app->getMenu();
$id = 474;
$link = JRoute::_($menu->getItem($id)->link);
?>
<script>
$(document).ready(function(){
var $link = $('<a>',{
class: 'all-news-link',
href: <?php echo json_encode( $link ); ?>
});
$('#custom-module .moduletable:nth-child(2) h3').append($link);
});
</script>
But it is not getting menu id 474 but 468 that is home page id. My SEF is also not turned on.
Upvotes: 1
Views: 1117
Reputation: 3731
You should be able to just do this:
$link = 'index.php?Itemid=474';
Assuming that the location that you print it on the page is picked up by the system plugin that routes output all will be well.
If that is actually what makes it to the page, then you would want to route it manually:
$link = JRoute::_('index.php?Itemid=474');
The router will handle getting the link for you.
Upvotes: 2