【问题标题】:How to get an url to a menuitem from an article id in joomla 1.6?如何从 joomla 1.6 中的文章 ID 获取菜单项的 URL?
【发布时间】:2011-10-12 04:15:39
【问题描述】:

我正在编写一个包含文章的模块。我希望这些文章以“阅读更多”按钮结束。如果存在这样的菜单项,则此按钮应重定向到指向整篇文章的菜单项,如果不存在,则应重定向到该文章(如 component=com_content&id=... 等)。

现在我正在使用带有 id 的 JRoute:

$url = JRoute::_( 'index.php?option=com_content&view=article&id='.$article->id );

但这会返回以下网址:

$url  = "http://example.com/option=com_content&view=article&id=1"

这指向正确的文章,但对搜索引擎不友好(它已打开,支持 .htaccess)并且它指向的页面与指向该文章的菜单项不同。

我确定它必须与 JRoute 做一些事情,但我找不到任何关于如何使这项工作发挥作用的资源。

有什么想法吗?谢谢!

【问题讨论】:

    标签: joomla seo url-routing joomla-extensions joomla1.6


    【解决方案1】:

    尝试使用 ComponentHelperRoute:

    $link = JRoute::_(ContentHelperRoute::getArticleRoute($article->slug, $article->catslug, $article->sectionid));
    

    【讨论】:

    • 谢谢,在搞砸了一点并对 getArticleRoute 进行了更多研究之后,我发现这段代码最终使它适用于我的情况: $url = JRoute::_(ContentHelperRoute: :getArticleRoute($article->id, $article->catid));
    猜你喜欢
    • 2013-05-23
    • 2011-05-30
    • 1970-01-01
    • 1970-01-01
    • 2014-04-13
    • 1970-01-01
    • 2011-02-14
    • 2012-10-14
    • 1970-01-01
    相关资源
    最近更新 更多