How to get article text by article ID in Joomla?

前端 未结 4 1440
长发绾君心
长发绾君心 2021-01-12 04:02

I want to get article text by passing article ID from the joomla template.

4条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-12 04:41

    Simple, providing you sending an article id with post/get and using variable "id" as its number:

    $articleId = JRequest::getInt('id');
    $db =& JFactory::getDBO();
    
    $sql = "SELECT fulltext FROM #__content WHERE id = ".intval($articleId);
    $db->setQuery($sql);
    $fullArticle = $db->loadResult();
    
    if(!strlen(trim($fullArticle))) $fullArticle = "Article is empty ";
    

    EDIT: to get articleId from anywhere:

    $articleId = (JRequest::getVar('option')==='com_content' && JRequest::getVar('view')==='article')? JRequest::getInt('id') : 0;
    

提交回复
热议问题