Show only single category posts on WordPress archive page

Here is the code you can use to show only single category posts on wordpress archive page.

function my_custom_get_posts( $query ) {

if ( $query->is_archive() ) {
$blog_term = get_term_by(‘slug’, ‘your-blogcategry-slug-name’, ‘category’);
$blog_term_id = $blog_term->term_id;
$query->set(‘cat’, $blog_term_id);
}
}
add_action( ‘pre_get_posts’, ‘my_custom_get_posts’, 1 );

Magento2 admin account disabled error

Hello All,

If you get issue something below on the Magento2 login page

 

 

Simply below query to database via phpmyadmin.

Example is for reset password for admin user.

UPDATE admin_user SET password = CONCAT(SHA2(‘xxxxxxxxNewPassword’, 256), ‘:xxxxxxxx:1’) WHERE username = ‘admin’;

NewPassword : Replace it with your password.

 

Hope it will work.

Get Magento catalog image

Today  I will show you how you can get the magento catalog image via code on any page. Please use below code and you will be done!!

 

Mage::helper('catalog/image')->init($product, 'thumbnail')->resize(100);

Exclude a category id from category collection in Magento

Please use the below code for exclude a category id from category collection in Magento

<?php
      $allCategories = Mage::getModel('catalog/category')
                       ->getCollection()
                       ->addAttributeToSelect('*')
                       ->addAttributeToFilter('level',2)
                       ->addAttributeToFilter('entity_id', array('nin' => 69))
                       ->addIsActiveFilter(); 

?>

Get Categories and Its Sub Categories in Magento

Today I will show you how you can fetch magento categories and its subcategories. Use below code

 

<?php 
$_helper = Mage::helper('catalog/category');
$_categories = $_helper->getStoreCategories();
if (count($_categories) > 0){
    foreach($_categories as $_category){
        $_category = Mage::getModel('catalog/category')->load($_category->getId());
        $_subcategories = $_category->getChildrenCategories();
        if (count($_subcategories) > 0){
            echo $_category->getName();
            echo $_category->getId();  
            echo $_category->getUrl();    
            foreach($_subcategories as $_subcategory){
                 echo $_subcategory->getName();
                 echo $_subcategory->getId();
                 echo $_subcategory->getUrl();
            }
        }
    }
}
?>

To show only one category where 2 is your main category id

<?php 
$category = Mage::getModel('catalog/category')->load(2);
$subcategories = $category->getChildrenCategories();
if (count($subcategories) > 0){
    echo $category->getName();
    foreach($subcategories as $subcategory){
         echo $subcategory->getName();
    }
}
?>