0

I have an Aheadworks blog module for Magento 2.

On the blog list page, breadcrumbs are displaying and I want to display breadcrumbs in the blog post view also.

Please suggest any solution.

Thanks,

1 Answer 1

0

Hello you have to add breadcrumbs using an XML file like:

<referenceBlock name="breadcrumbs">
  <action method="addCrumb">
    <argument name="crumbName" xsi:type="string">Home</argument>
    <argument name="crumbInfo" xsi:type="array">
        <item name="title" xsi:type="string">Home</item>
        <item name="label" xsi:type="string">Home</item>
        <item name="link" xsi:type="string">/</item>
    </argument>
  </action>
  <action method="addCrumb">
    <argument name="crumbName" xsi:type="string">Page name</argument>
    <argument name="crumbInfo" xsi:type="array">
        <item name="title" xsi:type="string">Page name</item>
        <item name="label" xsi:type="string">Page name</item>
        <item name="link" xsi:type="string">Page url </item>
    </argument>
  </action>
</referenceBlock>

Also, you have to add breadcrumbs using PHP controller file like:

public function execute() {
    $resultPageFactory = $this->resultPageFactory->create();

    // Add breadcrumb
    /** @var \Magento\Theme\Block\Html\Breadcrumbs */
    $breadcrumbs = $resultPageFactory->getLayout()-> 
    getBlock('breadcrumbs');
    $breadcrumbs->addCrumb('home', [
        'label' => __('Home'),
        'title' => __('Home'),
        'link' => $this->_url->getUrl('')
            ]
    );
    $breadcrumbs->addCrumb('custom_module', [
        'label' => __('Test'),
        'title' => __('Test')
            ]
    );
    return $resultPageFactory;
}
2
  • Hi @Bhavin , How to add the dynamic blog post name in above xml. Please suggest. Dec 24, 2021 at 7:48
  • @kirankumar, I change the answer you have to check again. Dec 24, 2021 at 12:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.