Magento 2: How to Get Subcategories of Specific Parent Category



<?php
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$catId = 2; // Parent Category ID
$subcategory = $objectManager->create('Magento\Catalog\Model\Category')->load($catId);
$subcats = $subcategory->getChildrenCategories();
$_helper = $this->helper('Magento\Catalog\Helper\Output');
?>
<ul class="sub-cat">
<?php
foreach ($subcats as $subcat) {
$_category = $objectManager->create('Magento\Catalog\Model\Category')->load($subcat->getId());
$_outputhelper = $this->helper('Magento\Catalog\Helper\Output');
$subcaturl = $subcat->getUrl();
$_imgHtml = '';
if ($_imgUrl = $_category->getImageUrl()) {
$_imgHtml = '<img src="' . $_imgUrl . '" />';
$_imgHtml = $_outputhelper->categoryAttribute($_category, $_imgHtml, 'image');
/* @escapeNotVerified */

} ?>
< li>
< div class="cat-image">
< a href="<?php echo $subcaturl ?>"><?php echo $_imgHtml;?></a>
< /div>
< div class="info">
< h4><?php echo $subcat->getName(); ?></h4>
< a class="link" href="<?php echo $subcaturl ?>"><?php /* @escapeNotVerified */ echo __('View more') ?></a></div>
< /li>
< ?php } ?>
< /ul>

Magento 2: Add new tab in Product detail page


New tab in product detail page is very easy task with product attribute. Use below steps and check it out.

Step 1. Create Product Attribute “video”.

Step 2. Create file “catalog_product_view.xml” in the app/design/frontend/{vender name}/{theme name}/Magento_Catalog/layout

In the file write the below code:


<!-- this is code to add new tab start -->
<referenceBlock name="product.info.details">
<block class="Magento\Catalog\Block\Product\View\Description" name="product.info.video" template="product/view/attribute.phtml" group="detailed_info">
<arguments>
<argument name="at_call" xsi:type="string">getVideo</argument>
<argument name="at_code" xsi:type="string">video</argument>
<argument name="css_class" xsi:type="string">video</argument>
<argument name="at_label" xsi:type="string">none</argument>
<argument name="title" translate="true" xsi:type="string">Video</argument>
</arguments>
</block>
</referenceBlock>
<!-- this is code to add new tab end -->

Now check in the Detail page.

Magento2- Display Static Block in Phtml file & CMS page


In XML File:

<referenceContainer name="content">
<block class="Magento\Cms\Block\Block" name="block_identifier">
<arguments>
<argument name="block_id" xsi:type="string">block_identifier</argument>
</arguments>
</block>
</referenceContainer>

In Phtml File:

<?php echo $block->getLayout()->createBlock('Magento\Cms\Block\Block')->setBlockId('block_identifier')->toHtml();?>

in CMS Content:

{{block class="Magento\\Cms\\Block\\Block" block_id="block_identifier"}}