【问题标题】:List all articles assigned to a Joomla! category列出分配给 Joomla! 的所有文章!类别
【发布时间】:2013-03-08 08:01:25
【问题描述】:

在文章的模板覆盖 (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 或使用像 "list of articles" 这样的插件。

【问题讨论】:

  • 你试过什么?为什么你认为这里需要更改 php-code?​​span>

标签: joomla joomla2.5


【解决方案1】:

这就是我正在使用的(在使用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 />";
}

【讨论】:

  • 如何使用此查询获取每篇文章的自定义字段?
【解决方案2】:

最好使用页面上的模块。 扩展>模块管理器 新的 文章分类 然后在选项中选择过滤到“我的子猫”而不是所有类别 然后将其分配给要显示列表的页面的菜单项。要么所有页面,要么只有一两个

【讨论】:

    猜你喜欢
    • 2014-04-19
    • 2013-05-12
    • 2016-02-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-10
    • 2014-09-07
    • 1970-01-01
    相关资源
    最近更新 更多