简体   繁体   中英

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.

$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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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