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”它看起来更好,但将类添加到参数列表不起作用)。有任何想法吗? –