简体   繁体   English

Joomla模块获取当前文章标题

[英]Joomla module get current article title

I'm trying to build a module that should show the article title of the current article viewed. 我正在尝试构建一个模块,该模块应显示当前查看文章的文章标题。

I've started from this code in my default.php layout that shows the title of the page, but I need to edit it so that it shows the article title and not the page title. 我从default.php布局中的该代码开始,该页面显示页面的标题,但是我需要对其进行编辑,以便它显示文章标题而不是页面标题。

$heading = $document->getTitle();

How should I edit it to get the article title instead of the page title? 我应该如何编辑它以获得文章标题而不是页面标题?

If this is in the normal article view, the following should work: 如果在普通文章视图中,这应该起作用:

$input = JFactory::getApplication()->input;
$id = $input->getInt('id', 0);
if(
  $id > 0 
  && $input->getString('option') == 'com_content' 
  && $input->getString('view') == 'article'
) {
    $c = JTable::getInstance('content'); 
    $c->load($id);
    echo $c->title;
}

I've solved this way: 我已经解决了这种方式:

$option = JRequest::getCmd('option');
$view = JRequest::getCmd('view');
if ($option=="com_content" && $view=="article") {
    $ids = explode(':',JRequest::getString('id'));
    $article_id = $ids[0];
    $article =& JTable::getInstance("content");
    $article->load($article_id);

    $heading = $article->get("title");
}

Not sure it's the correct/best solution, but it seems work at the moment. 不确定这是正确/最佳的解决方案,但目前看来可行。 Any suggestion, comment about this code or better implementation? 关于此代码或更好的实现有什么建议,评论吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM