在本教程中,您將學(xué)習(xí)如何為特定的Joomla文章創(chuàng)建模板覆蓋。
我將向您展示如何創(chuàng)建可用于單個(gè)Joomla文章的自定義布局。
步驟1.創(chuàng)建模板覆蓋
轉(zhuǎn)到擴(kuò)展程序 > 模板 > 模板:

向下滾動(dòng)并單擊[您的模板名稱] - 詳細(xì)信息和文件。對(duì)于此示例,我們使用的是Breeze模板,但這也適用于您的模板。
現(xiàn)在點(diǎn)擊查找文章布局文件:
- 創(chuàng)建替代
- Components
- com_content
- 文章

單擊文章布局文件后,Joomla將自動(dòng)創(chuàng)建可用作替代的文件的副本。
新文件位于/ templates / yourtemplate / html / com_content / article / 您可以在下面看到這些新文件:

在該文件夾中,我們還有兩個(gè)步驟:
刪除default.xml文件
將兩個(gè)PHP文件重命名為breeze.php 和breeze_links.php
該模板的核心部件是一個(gè)奇妙的簡(jiǎn)單的工具來創(chuàng)建覆蓋文件,但它也有局限性。例如,當(dāng)您的當(dāng)前模板已經(jīng)有單個(gè)文章的模板覆蓋時(shí),它不能很好地工作。在這種情況下,有必要手動(dòng)復(fù)制文件:
從/ components / com_content / views / article / tmpl /復(fù)制default.php和default_links.php
將具有新名稱的文件:breeze.php和breeze_links.php分別粘貼到/ templates / yourtemplate / html / com_content / article /中
步驟2.自定義新布局
在Notepad ++等代碼編輯器中打開 breeze.php文件
在此示例中,我們將使用列來顯示左側(cè)的圖像和右側(cè)的完整文本
更改第173到187行之間可以找到的代碼:
<div class="pull-<?php echo htmlspecialchars($imgfloat); ?> item-image"> <img
<?php if ($images->image_fulltext_caption):
echo 'class="caption"'.' title="' .htmlspecialchars($images->image_fulltext_caption) . '"';
endif; ?> src="/<?php echo htmlspecialchars($images->image_fulltext); ?>" alt="<?php echo htmlspecialchars($images->image_fulltext_alt); ?>"/> </div>
<?php endif; ?>
<?php
if (!empty($this->item->pagination) && $this->item->pagination && !$this->item->paginationposition && !$this->item->paginationrelative):
echo $this->item->pagination;
endif;
?>
<?php if (isset ($this->item->toc)) :
echo $this->item->toc;
endif; ?>
<?php echo $this->item->text; ?>
我們將通過使用自舉類的形象和全文包裝成兩列row-fluid和span6
這是代碼在更新后應(yīng)該如何看待:
<div class="row-fluid">
<div class="span6">
<div class="pull-<?php echo htmlspecialchars($imgfloat); ?> item-image"> <img
<?php if ($images->image_fulltext_caption):
echo 'class="caption"'.' title="' .htmlspecialchars($images->image_fulltext_caption) . '"';
endif; ?> src="/<?php echo htmlspecialchars($images->image_fulltext); ?>" alt="<?php echo htmlspecialchars($images->image_fulltext_alt); ?>"/> </div>
</div>
<div class="span6">
<?php echo $this->item->text; ?>
</div>
</div>
<?php endif; ?>
<?php
if (!empty($this->item->pagination) && $this->item->pagination && !$this->item->paginationposition && !$this->item->paginationrelative):
echo $this->item->pagination;
endif;
?>
<?php if (isset ($this->item->toc)) :
echo $this->item->toc;
endif; ?>
步驟3.啟用新布局
在文章設(shè)置中選擇此布局時(shí),此布局將起作用。
轉(zhuǎn)到內(nèi)容 > 文章 >您的文章。
轉(zhuǎn)到選項(xiàng)選項(xiàng)卡> 備用布局 > breeze

單擊“ 保存并關(guān)閉”。
在前端打開文章以查看新布局:






