How to get article text by article ID in Joomla?

Aryan G picture Aryan G · Aug 28, 2011 · Viewed 35.8k times · Source

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

Answer

WooDzu picture WooDzu · Aug 28, 2011

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;