繁体   English   中英

如何在Joomla中通过文章ID获取文章文本?

[英]How to get article text by article ID in Joomla?

我想通过从joomla模板传递文章ID来获取文章文本。

很简单,如果您发送带有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;

尝试这种技术:

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

按照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来自组件/插件参数,例如:

  1. 从内部组件:

     $app = JFactory::getApplication(); $params = $app->getParams(); $param = $params->get('terms_article_id'); 
  2. 从其他组成部分:

     $params = JComponentHelper::getParams('com_mycom'); $id = $params->get('terms_article_id'); 
  3. 从模板的php文件中获取模块参数:

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

Joomla有从sql表获取内容的默认脚本。

这篇文章(#__content)

获取文章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>";

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM