dongzhuo1498 2013-05-28 14:30
浏览 435
已采纳

Joomla模块,从文章ID获取菜单ID(ItemID)

So i've been searching and testing for a couple days and can't seem to figure this out.

I'm using the K2 content module and I need to add "?Itemid=111" to the end of the URL's it generates for the "Read More" link on pages.

This is not done by default and i've found where I can add it, but i'm having problems getting the Itemid (menu id) from the article id.

All the examples i've found use

$app   = JFactory::getApplication();
$menu   = $app->getMenu();
$activeId = $menu->getActive()->id;

And that works, whenever you're on that page, and it does add the correct ID. But for the articles I display on the homepage it does not work correctly as it adds the Itemid (menu id) of the homepage, and not the menu id of that specific article.

Before when using Joomla 1.5 I would use the built-in function

getItemid($articleid)

That doesn't seem to work for me anymore.

Does anybody have any suggestions or can anybody point me in the right direction on how I could solve this and "Get menu id (Itemid) from the article id"?

Thanks!!!

  • 写回答

1条回答 默认 最新

  • douda5706 2013-05-29 08:00
    关注

    You can get menu id of an article using the below code-

    $link = 'index.php?option=com_content&view=article&id='.(int)$articleId ;           
    $menu = JSite::getMenu();
    $menuItem = $menu->getItems( 'link', $link, true );
    $Itemid = $menuItem->id;
    

    Hope this will help.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 .net core 并发调用接口问题
  • ¥15 网上各种方法试过了,pip还是无法使用
  • ¥15 用verilog实现tanh函数和softplus函数
  • ¥15 Hadoop集群部署启动Hadoop时碰到问题
  • ¥15 求京东批量付款能替代天诚
  • ¥15 slaris 系统断电后,重新开机后一直自动重启
  • ¥15 QTableWidget重绘程序崩溃
  • ¥15 谁能帮我看看这拒稿理由啥意思啊阿啊
  • ¥15 关于vue2中methods使用call修改this指向的问题
  • ¥15 idea自动补全键位冲突