Trong magento 2.0, làm cách nào tôi có thể thêm các liên kết hàng đầu mới và xóa liên kết hiện có bằng xml


9

ứng dụng / thiết kế / frontend / Amydus / test / Magento_Theme / layout / default.xml

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceContainer name="header.container">            
            <block class="Magento\Framework\View\Element\Html\Myblock" name="header.myblock">
                <arguments>
                    <argument name="css_class" xsi:type="string">header links</argument>
                </arguments>
            </block>
        </referenceContainer>
        <referenceBlock name="top.links">
            <block class="Magento\Framework\View\Element\Template" name="tlink.them" before="-" template="Magento_Theme::html/header.phtml"/>
        </referenceBlock>
        <referenceBlock name="logo">
            <arguments>
                <argument name="logo_img_width" xsi:type="number">148</argument>
                <argument name="logo_img_height" xsi:type="number">43</argument>
            </arguments>
        </referenceBlock>
        <referenceContainer name="footer">
            <block class="Magento\Store\Block\Switcher" name="store_switcher" as="store_switcher" after="footer_links" template="switch/stores.phtml"/>
        </referenceContainer>
        <referenceBlock name="report.bugs" remove="true"/>
        <move element="copyright" destination="before.body.end"/>
    </body>
</page>

ứng dụng / thiết kế / frontend / Amydus / test / Magento_Theme / samples / html / header.phtml

<?php 
    $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
    $custSession = $objectManager->get('Magento\Customer\Model\Session');
?>
<?php switch ($block->getShowPart()):
    case 'welcome': ?>
        <!-- <li class="greet welcome" data-bind="scope: 'customer'">
            <span data-bind="text: customer().fullname ? $t('Welcome, %1!').replace('%1', customer().fullname) : '<?=$block->escapeHtml($welcomeMessage) ?>'"></span>
        </li> -->
        <li><a style="margin: 3px 0 0 8px;" href="#"><span>CALL US AT - 9560740007</span></a></li>
        <li class=" login_seprator"> | </li>
        <li class="easy-return" ><a style="margin: 3px 0 0 8px;" href="#">  <span >EASY RETURNS & EXCHANGE</span></a>
        </li>
        <li class=" login_seprator"> | </li>                        
        <?php if(!$custSession->isLoggedIn()): ?>
            <li class="hi_li"><span class="guest-color">HI GUEST</span></li>
        <?php else: ?>
            <li class="hi_li"><span><?php echo 'Hi '.$custSession->getCustomer()->getName(); ?></span></li>
        <?php endif; ?>
        <li class=" login_seprator"> | </li>
        <li class="first last top-links-a">
            <?php if($custSession->isLoggedIn()): ?>
                <a class="" title="Log Out" href="#">LOG OUT</a>
            <?php else: ?>
                <a class="" title="Log In" href="#">LOGIN</a>
            <?php endif; ?>
        </li> 

        <script type="text/x-magento-init">
        {
            "*": {
                "Magento_Ui/js/core/app": {
                    "components": {
                        "customer": {
                            "component": "Magento_Customer/js/view/customer"
                        }
                    }
                }
            }
        }
        </script>
    <?php break; ?>

    <?php case 'other': ?>
        <?php echo $block->getChildHtml(); ?>
    <?php break; ?>

<?php endswitch; ?>

Câu trả lời:


28

Nếu bạn mở rộng Luma Theme

ứng dụng / thiết kế / frontend / Amydus / test / 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>
       <!--  you can easly add New links with following code -->
        <referenceBlock name="header.links">
               <!-- Contact us Link -->
            <block class="Magento\Framework\View\Element\Html\Link" name="contactus.link" after="register-link">
                <arguments>
                    <argument name="label" xsi:type="string" translate="false">Constact Us</argument>
                    <argument name="path" xsi:type="string" translate="false">contact-us</argument>
                </arguments>
            </block>
            <!-- CMS Page Link Link -->
            <block class="Magento\Framework\View\Element\Html\Link" name="aboutus.link" after="contactus.link">
                <arguments>
                    <argument name="label" xsi:type="string" translate="false">about Us</argument>
                    <argument name="path" xsi:type="string" translate="false">about-us</argument>
                </arguments>
            </block>

             <!--  you can easly Remove  links with following code -->
            <referenceBlock name="register-link" remove="true" />           <!--for Create Account Link-->
            <referenceBlock name="authorization-link" remove="true" />      <!--for Sign In Link  -->
            <referenceBlock name="wish-list-link" remove="true" />          <!--for WishList Link-->
            <referenceBlock name="my-account-link" remove="true" />         <!--for My Account Link-->

        </referenceBlock>
    </body>
</page>

Nếu bạn mở rộng Chủ đề trống

ứng dụng / thiết kế / frontend / Amydus / test / 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>
       <!--  you can easly add New links with following code -->
        <referenceBlock name="top.links">
               <!-- Contact us Link -->
            <block class="Magento\Framework\View\Element\Html\Link" name="contactus.link" after="register-link">
                <arguments>
                    <argument name="label" xsi:type="string" translate="false">Constact Us</argument>
                    <argument name="path" xsi:type="string" translate="false">contact-us</argument>
                </arguments>
            </block>
            <!-- CMS Page Link Link -->
            <block class="Magento\Framework\View\Element\Html\Link" name="aboutus.link" after="contactus.link">
                <arguments>
                    <argument name="label" xsi:type="string" translate="false">about Us</argument>
                    <argument name="path" xsi:type="string" translate="false">about-us</argument>
                </arguments>
            </block>

             <!--  you can easly Remove  links with following code -->
            <referenceBlock name="register-link" remove="true" />           <!--for Create Account Link-->
            <referenceBlock name="authorization-link" remove="true" />      <!--for Sign In Link  -->
            <referenceBlock name="wish-list-link" remove="true" />          <!--for WishList Link-->
            <referenceBlock name="my-account-link" remove="true" />         <!--for My Account Link-->

        </referenceBlock>
    </body>
</page>

Dù sao trong Magento 2.1.3, liên kết đăng ký sẽ biến mất khi sử dụng giải pháp của bạn. Bất cứ ý tưởng tại sao?
— Tối đa

Làm thế nào về việc di chuyển các liên kết bên trong các <div class="header content"></div>yếu tố, nơi logo là? Bạn làm điều đó như thế nào?
— Razvan Zamfir

để xóa đăng nhập, bạn phải sử dụng "ủy quyền-liên kết-đăng nhập"
— Sagar Parikh SGR

5

Bạn cũng có thể sử dụng Magento\Customer\Block\Account\SortLinkInterfacelớp khối, cho phép bạn sắp xếp các liên kết trong khối top.links.

<referenceBlock name="top.links">
<block class="Magento\Customer\Block\Account\SortLinkInterface" name="newsletter_subscription_top_link">
    <arguments>
        <argument name="label" xsi:type="string" translate="true">Newsletter Subscription</argument>
        <argument name="path" xsi:type="string" translate="true">newsletter/manage</argument>
        <argument name="sortOrder" xsi:type="number">10</argument>
    </arguments>
</block>
</referenceBlock>
Khi sử dụng trang web của chúng tôi, bạn xác nhận rằng bạn đã đọc và hiểu Chính sách cookie và Chính sách bảo mật của chúng tôi.
Licensed under cc by-sa 3.0 with attribution required.