0
A
回答
1
請寫在default.xml中文件的代碼下面與位置
vendor/magento/module-theme/view/frontend/layout
你的頁面名稱和URL現在取代靜態的CMS頁面名稱和網址。
<referenceContainer name="catalog.topnav">
<block class="Magento\Framework\View\Element\Html\Link\Current" name="your.link">
<arguments>
<argument name="label" xsi:type="string">Link-name</argument>
<argument name="path" xsi:type="string">Link-url</argument>
</arguments>
</block>
</referenceContainer>
0
Magento2添加CMS頁面鏈接到菜單或Magento2添加自定義鏈接菜單,
首先,創建一個模塊。
文件:
app\code\{VendorName}\{ModuleName}\etc\module.xml
app\code\{VendorName}\{ModuleName}\registration.php
app\code\{VendorName}\{ModuleName}\composer.json
二:創建di.xml,我們將DEFI NE插件
app\code\{VendorName}\{ModuleName}\etc\di.xml
代碼爲
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\Theme\Block\Html\Topmenu">
<plugin name="add_cms_menu" type="{VendorName}{ModuleName}\Plugin\Topmenu" sortOrder="1" />
</type>
</config>
三:創建di.xml,我們將定義插件
app\code\{VendorName}\{ModuleName}\Plugin\Topmenu.php
代碼爲
<?php
namespace {VendorName}{ModuleName}\Plugin;
use Magento\Framework\Data\Tree\NodeFactory;
class Topmenu
{
protected $nodeFactory;
protected $_storeManager;
protected $_pageFactory;
protected $_urlBuilder;
public function __construct(
NodeFactory $nodeFactory,
\Magento\Cms\Model\PageFactory $pageFactory,
\Magento\Store\Model\StoreManagerInterface $storeManager,
\Magento\Framework\UrlInterface $urlBuilder
) {
$this->nodeFactory = $nodeFactory;
$this->_pageFactory = $pageFactory;
$this->_storeManager = $storeManager;
$this->_urlBuilder = $urlBuilder;
}
public function beforeGetHtml(
\Magento\Theme\Block\Html\Topmenu $subject,
$outermostClass = '',
$childrenWrapClass = '',
$limit = 0
) {
/* Showing Cms page About us at menu */
$page = $this->getCmspage('about-us');
if($page == null){
return;
}
$node = $this->nodeFactory->create(
[
'data' => [
'name' => $page->getTitle(),
'id' => $page->getIdentifier(),
'url' => $this->_urlBuilder->getUrl(null, ['_direct' => $page->getIdentifier()]),
'has_active' => false,
'is_active' => false // (expression to determine if menu item is selected or not)
],
'idField' => 'id',
'tree' => $subject->getMenu()->getTree()
]
);
$subject->getMenu()->addChild($node);
}
protected function getCmspage($identifier){
$page = $this->_pageFactory->create();
$pageId = $page->checkIdentifier($identifier, $this->_storeManager->getStore()->getId());
if (!$pageId) {
return null;
}
$page->setStoreId($this->_storeManager->getStore()->getId());
if (!$page->load($pageId)) {
return null;
}
if (!$page->getId()) {
return null;
}
return $page;
}
}
更多細節在
http://www.amitbera.com/magento2-add-a-cms-page-link-to-menu/
0
checkout出來要內<header>
添加鏈接添加到頂部導航鏈接到CMS頁面,圖庫
編輯/放置默認值。XML在這裏:
app/design/frontend/Vendor/theme/Magento_Theme/layout/default.xml
添加以下代碼:
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="catalog.topnav">
<block class="Magento\Framework\View\Element\Html\Link\Current" name="gallery.link">
<arguments>
<argument name="label" xsi:type="string">Gallery</argument>
<argument name="path" xsi:type="string">gallery</argument>
</arguments>
</block>
</referenceContainer>
</body>
</page>
這將鏈接添加到CMS頁面,畫廊,使用以下設置:
Title = Gallery
Url Key = gallery
Link = https://example.com/gallery/
添加下面的造型,以確保新鏈接正確對齊:
.navigation .nav.item {
margin: 0 10px 0 0;
display: inline-block;
position: relative;
}
相關問題
- 1. 在Magento中添加靜態鏈接到頂部導航菜單
- 2. Magento 2.0:在頁面模板中添加靜態塊
- 3. wordpress:在靜態頁面上顯示2篇文章+頁面導航
- 4. 添加導航菜單清空Magento CMS頁面?
- 5. Magento - 添加分層導航到自定義頁面
- 6. 將magento CMS頁面添加到導航欄
- 7. 添加引導輪播Magento的頁面
- 8. 動態導航到頁面
- 9. 將Wordpress添加到靜態HTML頁面?
- 10. 將_header.html.erb添加到靜態html頁面
- 11. MAGENTO - 不輸出靜態頁面內容
- 12. 動態html頁面導航
- 13. 在頁面內動態導航頁面
- 14. 使用Javascript動態添加導航至主頁面
- 15. 頁面末尾的靜態塊Magento
- 16. CMS頁面添加塊magento
- 17. 靜態HTML頁面導航到ASP.NET.MVC應用程序
- 18. 加載的頁面導航
- 19. 從主頁添加導航
- 20. wxPython動態添加頁面到嚮導
- 21. 將過濾分層導航添加到1列分類Magento中的頁面
- 22. Magento - 如何添加導航菜單
- 23. Magento - 如何在主頁的側欄添加靜態塊
- 24. 爲靜態Magento導航創建一個「actIve」狀態
- 25. Magento將產品添加到靜態塊
- 26. magento - 將BLOCKTYPE添加到靜態塊
- 27. Iphone開發:基本靜態頁面導航?
- 28. 如何在頁面之間導航時保持網格靜態?
- 29. 如何將頁面添加到多站點導航菜單中?
- 30. 靜態HTML到PHP導航
當我做這個「鏈接名稱」的新造型是怪異(這是其他鏈接的下面,旁邊不浮於鏈接。如果我添加類「level0」它看起來更好,但將類添加到參數列表不起作用)。有任何想法嗎? –