2

在文章 ( com_content/article/default.php) 的模板覆盖中,我必须打印所有文章标题,这些文章标题分配给由特定 ID 标识的类别(静态嵌入在我的代码中)。

这是一个简短的例子:

我有以下类别:

Uncategorized (id = 0)
Mycat (id = 1)
 |- My subcat (id = 2)
Mycat2 (id = 3)

有了这篇文章:

Travelling and the US -> MyCat
New York is a nice city -> My subcat
Give me some feedback -> MyCat2
...

在我的代码中,我现在想列出分配给 id = 1 类别的所有文章。此处的输出应如下所示:

Travelling and the US
New York is a nice city

更新:对于阅读此内容并需要相同内容的每个人:唯一的方法是编写一个普通的 SQL 查询并通过 Joomla 运行它!数据库 API 或使用“文章列表”之类的插件。

4

2 回答 2

3

这就是我正在使用的(在用于loadPosition在内容页面上显示的模块内)

//Use JModelLegacy to get all articles within $categoryID

$model = JModelLegacy::getInstance('Articles', 'ContentModel', array('ignore_request' => true));
$appParams = JFactory::getApplication()->getParams();
$model->setState('params', $appParams);
$model->setState('filter.category_id', 'YOUR CATEGORY ID HERE'); //change that to your Category ID
$model->setState('list.ordering', 'title');
$model->setState('list.direction', 'ASC');

$articlesCategory =  (array) $model->getItems();

foreach ($articlesCategory as $artCat) {
  $artCat =  (array) $artCat;
  echo $artCat['title']  . "<br /><br />";
}
于 2014-04-24T19:57:37.843 回答
1

最好使用页面上的模块。Extensions>Module Manager New Articles Category 然后在选项中选择过滤到“My subcat”而不是所有类别然后将其分配给要显示列表的页面的菜单项。要么所有页面,要么只有一两页

于 2013-03-08T12:51:30.280 回答