2013-03-08 22 views
2

在文章模板覆蓋(com_content/article/default.php)中,我必須打印所有分配給由特定ID(靜態嵌入在我的代碼中)標識的類別的文章標題。列出所有分配給Joomla的文章!類別

下面是一個簡單的例子:

我有以下幾類:

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 

UPDATE: 大家誰讀這一點,需要同樣的:做這或者是寫一個簡單的SQL查詢和通過的Joomla運行它的唯一途徑!數據庫API或使用像"list of articles"這樣的插件。

+0

你嘗試過什麼(使用loadPosition顯示的內容頁面上的模塊內)?你爲什麼認爲這裏需要改變php代碼? – FredFloete 2013-03-08 09:12:29

回答

1

最好使用什麼會是頁面上的模塊。 擴展>模塊管理器 新 文章分類 然後在選項中選擇過濾到只是「我的子帖」不是所有的類別 然後將其分配給您想要顯示列表的頁面的菜單項。要麼所有頁面或只是一個或兩個

0

這是我使用的是什麼

//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 />"; 
} 
相關問題