How to get article text by article id in Joomla?

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

+8
php joomla
source share
4 answers

Simple, providing you with sending the article id using post / get and using the id variable 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: Get the article from anywhere:

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

try this technique:

 $article = JControllerLegacy::getInstance('Content')->getModel('Article')->getItem($articleId); echo $article->introtext; 
+5
source share

Get the text of the article by the article id in Joomla 2.5 (3 will also work in accordance with the documents):

 $article =& JTable::getInstance("content"); $article->load($id); $content = '<h3>'. $article->get("title").'</h3>'; $content .= $article->get("introtext"); // introtext and/or fulltext 

And the article identifier is obtained from the component / plugin parameters, for example:

  • From within a native component:

     $app = JFactory::getApplication(); $params = $app->getParams(); $param = $params->get('terms_article_id'); 
  • From another component:

     $params = JComponentHelper::getParams('com_mycom'); $id = $params->get('terms_article_id'); 
  • Get module parameter from php file template:

     $module = JModuleHelper::getModule('mod_mymodule'); $params = new JRegistry($module->params); // or $mymoduleParams if few used $id = (int) $headLineParams['count']; 
+5
source share

Joomla has a default script to retrieve content from a sql table.

Here's the article (#__ content)

Get article id:

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

To get the content of an article:

 $table_plan = & JTable::getInstance('Content', 'JTable'); $table_plan_return = $table_plan->load(array('id'=>$articleId)); echo "<pre>";print_r($table_plan->introtext);echo "</pre>"; 
+4
source share

All Articles