8

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

4 Answers 4

17

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;
4
  • Thank you. Is there any way to get article text by passing article ID from joomla template?
    – Aryan G
    Aug 29, 2011 at 7:28
  • articleId = JRequest::getInt('id');
    – WooDzu
    Aug 29, 2011 at 7:57
  • 1
    or if you wanted to use a fixed article id, use template parameters: docs.joomla.org/Template_parameters
    – WooDzu
    Aug 29, 2011 at 8:03
  • Can yoг hint me how to get the text until the cut, pls ? May 27, 2012 at 14:54
7

try this technique:

$article = JControllerLegacy::getInstance('Content')->getModel('Article')->getItem($articleId);
echo $article->introtext;
1
  • 1
    It works as long your are accessing the article content from another article. But once you are in the template code, it stop working
    – Samsky
    Mar 22, 2015 at 12:27
7

Get article text by article ID in Joomla 2.5 (3 will work also according docs) plugins:

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

And article id is got from component/plugin parameters for example:

  1. From inside own component:

    $app = JFactory::getApplication();
    $params = $app->getParams();
    $param = $params->get('terms_article_id');
    
  2. From other component:

    $params = JComponentHelper::getParams('com_mycom');
    $id = $params->get('terms_article_id');
    
  3. Get Module Parameter from template's php file:

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

Joomla has the default script for getting content from sql table.

Here article (#__content)

To Get Article Id:

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

To get Article content:

$table_plan         = & JTable::getInstance('Content', 'JTable');
$table_plan_return  = $table_plan->load(array('id'=>$articleId));
echo "<pre>";print_r($table_plan->introtext);echo "</pre>";
1
  • 1
    this solution worked for me, even by accessing article context from a template php
    – Samsky
    Mar 22, 2015 at 12:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.