在蘋果CMS中調用當前欄目下的視頻,可通過模板標籤{maccms:vod}的type="current"參數實現。以下是具體步驟和擴展配置說明:
{maccms:vod num="12" type="current" order="desc" by="hits"}
<li class="clear">
<a class="thumbnail-link"
href="{:mac_url_vod_play($vo,1,1)}"
rel="bookmark">
<div class="thumbnail-wrap">
<img src="{$vo.vod_pic}" />
<div class="video-duration">{$vo.vod_year}</div>
</div>
</a>
<div class="entry-wrap">
<a href="{:mac_url_vod_play($vo,1,1)}"
rel="bookmark">{$vo.vod_name}</a>
<div class="entry-meta">
<span class="entry-views">
<i class="fa fa-eye"></i>
<span class="view-count">{$vo.vod_hits}次觀看</span>
</span>
<span class="sep"> · </span>
<span class="entry-date">{$vo.vod_time|mac_day}</span>
</div>
</div>
</li>
{/maccms:vod}一、基礎調用代碼
在模板文件(如vodplay.html或欄目頁模板)中添加以下代碼:
{maccms:vod num="10" type="current" order="desc" by="time"}- 參數解析:
num="10":調用10條視頻(可按需修改)。type="current":限定爲當前欄目下的視頻。order="desc" by="time":按發佈時間降序排列(最新視頻優先)。
二、擴展配置場景
1. 按點擊量排序(熱門視頻)
{maccms:vod num="10" type="current" order="desc" by="hits"}2. 隨機調用本欄目視頻
{maccms:vod num="10" type="current" order="rand"}3. 僅調用推薦值≥5的視頻
{maccms:vod num="10" type="current" order="desc" by="hits" level="5"}(需提前在視頻編輯頁設置推薦值)
4. 排除當前視頻本身(避免重複推薦)
{maccms:vod num="10" type="current" id="!{$maccms.vod.vod_id}"}三、前端展示示例
<div class="current-videos">
{maccms:vod num="10" type="current" order="desc" by="time"}
<div class="video-card">
<a href="{$vo.vod_play_url}">
<img src="{$vo.vod_pic}" alt="{$vo.vod_name}">
<h3>{$vo.vod_name}</h3>
<p>更新至:{$vo.vod_serial}</p>
</a>
</div>
{/maccms:vod}
</div>
<style>
.current-videos { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 20px; }
.video-card img { width: 100%; height: 280px; object-fit: cover; border-radius: 8px; }
.video-card h3 { font-size: 16px; margin: 8px 0; }
.video-card p { color: #666; font-size: 14px; }
</style>四、關鍵注意事項
- 欄目ID匹配
- 確保模板文件與目標欄目綁定(如欄目頁模板需對應正確分類ID)。
- 若在播放頁調用,
type="current"會自動繼承當前視頻所屬欄目。
- 性能優化
- 視頻量較大時,建議在後臺 系統 → 計劃任務 中開啓“自動生成分類緩存”。
- 避免在首頁等高併發頁面過度調用(如
num值不宜過大)。
- 緩存清理
- 修改模板後,需在蘋果CMS後臺 右上角點擊“清緩存”,否則前端可能不更新。
五、高級應用場景
1. 結合標籤過濾
調用當前欄目且包含特定標籤的視頻(如“4K”標籤):
{maccms:vod num="10" type="current" tag="4K"}2. 跨欄目調用(但優先當前欄目)
若當前欄目視頻不足10條,自動補充其他欄目數據:
{maccms:vod num="10" type="current,other" order="rand"}3. 調用子欄目視頻
若當前欄目有子分類,需遞歸調用所有子欄目視頻:
{maccms:vod num="10" type="current,child" order="desc" by="time"}通過以上配置,可靈活實現當前欄目視頻的多樣化調用需求,適用於播放頁關聯推薦、欄目頁內容填充等場景。