获取文章(按 Id)介绍文本到自定义模块中

问题描述 投票:0回答:1

我正在 joomla 4 中开发一个自定义模块,它需要访问 Id 已知的特定文章的 introtext。

我正在寻找一个遵循最新编码标准的代码片段,并且最有可能在 joomla 5 出现时继续正常工作,而不是在信封背面草草记下的东西。

还没有尝试任何东西,所以什么都没有发生。

get article
1个回答
0
投票

您可以使用sql查询从_content表中获取introtext

/**
 * Get the introtext of an article
 * @param int $articleID
 * @return string the introtext
 */
function getArticleIntrotext($articleID) {
    $db = Factory::getContainer()->get('DatabaseDriver');
    // basic sql query... SELECT introtext FROM #__content WHERE id = $articleID
    $query = $db->getQuery(true)
        ->select($db->quoteName('introtext'))
        ->from($db->quoteName('#__content'))
        ->where($db->quoteName('id') . ' = ' . $articleID);
    $db->setQuery($query);
    $introtext = $db->loadResult();

    return $introtext;

}
© www.soinside.com 2019 - 2024. All rights reserved.