聯(lián)系官方銷售客服
1835022288
028-61286886
在迅睿CMS中,在首頁調(diào)用文章列表同時(shí)獲取每篇文章所在的欄目名和欄目鏈接,可以使用以下代碼:
```
<?php // 獲取文章列表 $module = 'news'; // 文章模塊名稱 $limit = 10; // 文章數(shù)量 $page = 1; // 當(dāng)前頁碼 $where = ''; // 文章篩選條件,可以為空 $order = 'updatetime DESC'; // 文章排序方式 $catid = ''; // 文章分類ID,可以為空 $list = \Phpcmf\Service::C()->module($module)->limit($limit)->page($page)->where($where)->order($order)->category($catid)->get_data(); // 遍歷文章列表,獲取每篇文章所在的欄目名和欄目鏈接 foreach ($list as $data) { $catid = $data['catid']; $cat = \Phpcmf\Service::C()->get_cache('module-' . $module . '-category', $catid); $cat_name = $cat['name']; // 欄目名 $cat_url = $cat['url']; // 欄目鏈接 $title = $data['title']; // 文章標(biāo)題 $url = $data['url']; // 文章鏈接 $description = $data['description']; // 文章描述 // 在這里輸出文章列表和每篇文章所在的欄目名和欄目鏈接 } ?>
```
這個(gè)代碼中,首先使用 \Phpcmf\Service::C()->module() 方法獲取文章列表,其中
$module 是文章模塊名稱,
$limit 是文章數(shù)量,
$page 是當(dāng)前頁碼,
$where 是文章篩選條件,
$order 是文章排序方式,
$catid 是文章分類ID。
獲取到文章列表之后,
使用 foreach 遍歷文章列表,
使用 \Phpcmf\Service::C()->get_cache() 方法獲取每篇文章所在的欄目信息,
其中 $cat_name 是欄目名,
$cat_url 是欄目鏈接。
可以在這里輸出文章列表和每篇文章所在的欄目名和欄目鏈接。
注意,這個(gè)代碼需要放置在首頁模板文件中,以顯示在網(wǎng)站首頁。如果你要在其他頁面調(diào)用文章列表,可以修改 $module 和 $limit 等參數(shù)來適應(yīng)不同的頁面需求。