Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Subcatagory Landing page
 
powelly04
Jr. Member
 
Total Posts:  5
Joined:  2012-07-02
 

I’m using the follow code as a static block as a subcategory landing page. The code works well but i cant change the image so it loads the thumbnail image from the subcategory instead of the image from the subcategory. The code a static block is live and availble to test on the following URL:

http://dasmotorsport.co.uk/cleaning-detailing/brand.html

the code in question is:

<?php
/* File Location
* /new/app/design/frontend/base/default/template/catalog/navigation
*/
?>
 
<div id="categories">
<
div class="col_full">
<
div class="listing">
 
<?php
 
    
function getThumbnailUrl($category)
    
{
    $cur_category
=Mage::getModel('catalog/category')->load($category->getId());
    
$layer Mage::getSingleton('catalog/layer');
    
$layer->setCurrentCategory($cur_category);
 
            
$url $this->getCurrentCategory()->getThumbnailUrl();
        return 
$url;
    
};
 
    
//Get the Current Category
    
$_maincategorylisting=$this->getCurrentCategory();   
 
    
// Iterate all categories in store
   
foreach ($this->getCurrentChildCategories() as $_category):
 
        
// If category is Active
        
if($_category->getIsActive()):
 
            
// Load the actual category object for this category
            
$cur_category Mage::getModel('catalog/category')->load($_category->getId());
 
            
// Load a random product from this category
            
$products Mage::getResourceModel('catalog/product_collection')->addCategoryFilter($cur_category);
            
$products->getSelect()->order(new Zend_Db_Expr('RAND()'))->limit(1);
 
            
$products->load();
 
            
// This a bit of a fudge - there's only one element in the collection
            
$_product null;
 
            foreach ( 
$products as $_product {}
 
            
if(isset($_product)):
            
?>

            
<div class="sub-category-listing" style="float: left;align:center;margin-left:70px;margin-right:auto; padding: 0px; text-align: center; width: 250px; ">
                <
div class="linkimage"><p><a href="<?php echo $this->getCategoryUrl($_category)?>" class="product-image">

            
<?php
            $layer 
Mage::getSingleton('catalog/layer');
            
$layer->setCurrentCategory($cur_category);
            
?>     
 
            <?
            
// If there is an image set for the category - Display it
            
if($_imgUrl=$this->getCurrentCategory()->getThumbnailUrl()):?>
                
<img src="<?php echo $_imgUrl ?>" style="padding: 10px;" alt="<?php echo $this->htmlEscape($_product->getName()) ?>" />
            
<?php endif; ?>
 
            <?
            
// If there is not a image set for that Category - Display a random product Image
            
if(!$_imgUrl):
 
            
// Let's load the category Model and grab the product collection of that category
 
            
$product_collection Mage::getModel('catalog/category')->load($_category->getId())->getProductCollection();
            
$product_collection->getSelect()->order(new Zend_Db_Expr('RAND()'))->limit(1);
 
            
// Now let's loop through the product collection and print the ID of every product
            
foreach($product_collection as $product{
 
            
// Get the product ID
            
$product_id $product->getId();
 
            
// Load the full product model based on the product ID
 
            
$full_product Mage::getModel('catalog/product')->load($product_id);
 
            
// Now that we loaded the full product model, let's access all of it's data
 
            // Let's get the Product Name
 
            
$product_name $full_product->getName();
 
            
// Let's get the Product URL path
 
            
$product_url $full_product->getProductUrl();
 
            
// Let's get the Product Image URL
 
            
$product_image_url $full_product->getThumbnailUrl();
 
            
// Let's print the product information we gathered and continue onto the next one
 
            
//End For Each
            
?>
            
                
                
<img src="<?php echo $product_image_url; ?>" width="135" height="135"  style="padding: 10px;" alt="<?php echo $this->htmlEscape($_product->getName()) ?>" />
            
<?php endif; ?>
            
</a>
                </
div>
            <
a href="<?php echo $this->getCategoryUrl($_category)?>">
            <
h2 class="product-name" style="margin-top: 10px;"><?php echo $_category->getName()?></a></h2>
            
<? if($_description=$this->getCurrentCategory()->getDescription()):?>
            
</p>
                
            
<?php endif; ?>
 
            
</div>
 
            
<?php
            
endif;
        endif;
    endforeach;
?>
</div>
<
br clear=all>
</
div>
</
div>

Any help would be great.

 
Magento Community Magento Community
Magento Community
Magento Community
 
powelly04
Jr. Member
 
Total Posts:  5
Joined:  2012-07-02
 

Any have any idea on how to correct the code to show thumbnails.

 
Magento Community Magento Community
Magento Community
Magento Community
 
powelly04
Jr. Member
 
Total Posts:  5
Joined:  2012-07-02
 

nearly their now thanks to me :D

I just don’t understand why it loads all subcategories, and not just the subcategories for the category which loads the landing page as its used withing a static block,

Here is my code as it stands now. Help would be great?

<?php
    $_categories 
Mage::getModel('catalog/category')
->
getCollection();
$_categories->addAttributeToSort('name''ASC');
    
$_categories->addAttributeToSelect('*');
    
$_categories->addAttributeToFilter('is_active'1);
    
$_categories->addAttributeToFilter('include_in_menu'1);      
    
$_collection $_categories->load();
?>
<div class="category-icon">
    
<?php
        $_no_of_columns 
= ($this->no_of_columns) ? $this->no_of_columns 7// No. of columns per row
        
$_img_path Mage::getBaseUrl('media').'catalog/category/';
    
?>
    <?php 
        
/**
         * Let's Iterate through categories not their sub categories
         * You can do the sub categories thing also, but I haven't included it here
         */
    
?>
    <?php 
if($_size = (count($_collection)-1) > 0): ?>
        <?php $_i 
0; foreach($_collection as $_category): ?>
        <?php 
if ($_i++ % $_no_of_columns == 0): ?>
        
        
        
        
        <?php 
endif; ?>
<div class="sub-category-listing" style="float: left; align:center; margin-left:0px;margin-right:25px; padding: 0px; text-align: center; width: 250px; display:block; ">


            
<?php if ($_imgUrl $_category->getThumbnail()): ?>

                
<a href="<?php echo $_category->getUrl(); ?>" title="<?php echo $_category->getName(); ?>">
                    <
span><img src="<?php echo $_img_path.$_imgUrl; ?>" /></span>
                </
a>
                <
h2>
                    <
a href="<?php echo $_category->getUrl(); ?>" title="<?php echo $_category->getName(); ?>">
                        
<?php echo $_category->getName(); ?>
                    
</a>
                </
h2>

        
<?php endif; ?>
</div>
        
<?php if ($_i $_no_of_columns == || $_i == $_cat_count): ?>

        
        
        <?php 
endif; ?>    
    <?php 
endforeach; ?>
    <?php 
else: ?>
    
<class="note-msg"><?php echo $this->__('There are no categories inserted.'?></p>
    
<?php endif; ?>
 
Magento Community Magento Community
Magento Community
Magento Community
 
powelly04
Jr. Member
 
Total Posts:  5
Joined:  2012-07-02
 

No one have any idea.

 
Magento Community Magento Community
Magento Community
Magento Community
 
powelly04
Jr. Member
 
Total Posts:  5
Joined:  2012-07-02
 

Does know one have any idea?

This post has been active now for 4 days.

 
Magento Community Magento Community
Magento Community
Magento Community
 
varun931
Jr. Member
 
Avatar
Total Posts:  4
Joined:  2012-09-05
Jaipur
 

Hi

Hope this help :

<?php
$obj 
= new Mage_Catalog_Block_Navigation();
$store_cats    $obj->getStoreCategories();
$current_cat     $obj->getCurrentCategory();
?>
 
<ul>
<?php $_helper Mage::helper('catalog/category'); ?>
<?php  $currentCategory 
Mage::registry('current_category'); ?>
 <?php  $currentCategory
->getId();
 
$_category Mage::getModel('catalog/category')->load($currentCategory->getId());
$subcat $currentCategory->getChildren();
 
    foreach(
$obj->getCurrentChildCategories() as $subcategory)
    
{
?>    
<li>
            <
div class="nutrition_block">
           <
a href="<?php echo Mage::getModel("catalog/category")->load($subcategory->getId())->getUrl(); ?>">
            <
img src="<?php echo Mage::getBaseUrl('media').'catalog/category/'.Mage::getModel("catalog/category")->load($subcategory->getId())->getThumbnail()?>" width="215" height="124" alt="" title="">
            </
a>
            <
p><strong><a href="<?php echo Mage::getModel("catalog/category")->load($subcategory->getId())->getUrl(); ?>"><?php echo $subcategory->getName();?></a> <img src="<?php echo $this->getSkinUrl('images/arrow01.png')?>" width="4" height="8" alt="" title=""></strong></p>
            <
p><?php echo Mage::getModel("catalog/category")->load($subcategory->getId())->getDescription(); ?></p>
            </
div>
      </
li>           
           
 
<?php  }?>

Thanks
Varun

 
Magento Community Magento Community
Magento Community
Magento Community
 
JAI S
Jr. Member
 
Total Posts:  13
Joined:  2008-12-15
 

Hello ...How did you do this?

I saw the image is displayed with every sub category on page :  http://dasmotorsport.co.uk/cleaning-detailing/brand.html and i need same thing to implement. Please help me

Thanks in advance.

 
Magento Community Magento Community
Magento Community
Magento Community
 
JAI S
Jr. Member
 
Total Posts:  13
Joined:  2008-12-15
 

It works for me by using your code...thanks

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top