phpjoomla

How to get article text by article ID in Joomla?


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


Solution

  • 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;