我希望通过从joomla模板传递文章ID来获取文章文本。
答案 0 :(得分:16)
简单,如果您发送带有post / get的文章ID并使用变量“id”作为其编号:
$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 ";
编辑:从任何地方获取articleId:
$articleId = (JRequest::getVar('option')==='com_content' && JRequest::getVar('view')==='article')? JRequest::getInt('id') : 0;
答案 1 :(得分:5)
尝试这种技巧:
$article = JControllerLegacy::getInstance('Content')->getModel('Article')->getItem($articleId);
echo $article->introtext;
答案 2 :(得分:5)
通过Joomla 2.5中的文章ID获取文章文本(3也将根据文档工作)插件:
$article =& JTable::getInstance("content");
$article->load($id);
$content = '<h3>'. $article->get("title").'</h3>';
$content .= $article->get("introtext"); // introtext and/or fulltext
文章ID来自组件/插件参数,例如:
来自内部组件:
$app = JFactory::getApplication();
$params = $app->getParams();
$param = $params->get('terms_article_id');
来自其他组成部分:
$params = JComponentHelper::getParams('com_mycom');
$id = $params->get('terms_article_id');
从模板的php文件中获取模块参数:
$module = JModuleHelper::getModule('mod_mymodule');
$params = new JRegistry($module->params); // or $mymoduleParams if few used
$id = (int) $headLineParams['count'];
答案 3 :(得分:4)
Joomla有从sql表获取内容的默认脚本。
这篇文章(#__内容)
获取文章ID:
$articleId = (JRequest::getVar('option')==='com_content' && JRequest::getVar('view')==='article')? JRequest::getInt('id') : 0;
获取文章内容:
$table_plan = & JTable::getInstance('Content', 'JTable');
$table_plan_return = $table_plan->load(array('id'=>$articleId));
echo "<pre>";print_r($table_plan->introtext);echo "</pre>";