php 如何通过 Joomla 中的文章 ID 获取文章文本?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7219876/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to get article text by article ID in Joomla?
提问by Aryan G
I want to get article text by passing article ID from the joomla template.
我想通过从 joomla 模板传递文章 ID 来获取文章文本。
回答by WooDzu
Simple, providing you sending an article id with post/get and using variable "id" as its number:
很简单,为您提供带有 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 ";
EDIT: to get articleId from anywhere:
编辑:从任何地方获取文章ID:
$articleId = (JRequest::getVar('option')==='com_content' && JRequest::getVar('view')==='article')? JRequest::getInt('id') : 0;
回答by aldo
try this technique:
试试这个技术:
$article = JControllerLegacy::getInstance('Content')->getModel('Article')->getItem($articleId);
echo $article->introtext;
回答by Arunas Bartisius
Get article text by article ID in Joomla 2.5 (3 will work also according docs) plugins:
在 Joomla 2.5(3 也可以根据文档工作)插件中通过文章 ID 获取文章文本:
$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:
文章 id 是从组件/插件参数中获取的,例如:
From inside own component:
$app = JFactory::getApplication(); $params = $app->getParams(); $param = $params->get('terms_article_id');
From other component:
$params = JComponentHelper::getParams('com_mycom'); $id = $params->get('terms_article_id');
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'];
从自己的组件内部:
$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'];
回答by Kathir
Joomla has the default script for getting content from sql table.
Joomla 具有从 sql 表中获取内容的默认脚本。
Here article (#__content)
这里的文章 (#__content)
To Get Article Id:
获取文章 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>";