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

2022-01-06 00:00:00 php joomla

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

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

推荐答案

简单,提供您发送带有 post/get 的文章 id 并使用变量id"作为其编号:

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 ";

从任何地方获取文章 ID:

to get articleId from anywhere:

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

相关文章