1

Unable to get Products when click on category.

Code:

<?php
    $_categories = Mage::getModel('catalog/category')->getCollection()
    ->addAttributeToSelect('*')
    ->addAttributeToFilter('is_active', 1);       

    foreach ($_categories as $_category)
        {  
            if($_category->getImageUrl())  
                {  
                    $catimg     = $_category->getImageUrl();  
?>
<div class="category1">  
<img src="<?php echo $catimg ;?>" alt="" />
  <a class="cate_btn" title="View the products for this category" href="<?php echo $_category->getUrl($_category) ;?>">View</a>
  </div> 

<?php } } ?>

when i click on view,it leads to following url:

rtd/index.php/catalog/category/view/s/cat1/id/3/

This Page gives error Message as Following:

Whoops, our bad...

The page you requested was not found, and we have a fine guess why.

        If you typed the URL directly, please make sure the spelling is correct.
        If you clicked on a link to get here, the link is outdated.

What can you do?
    Have no fear, help is near! There are many ways you can get back on track with Magento Store.

        Go back to the previous page.
        Use the search bar at the top of the page to search for your products.
        Follow these links to get you back on track!
        Store Home | My Account

Help me out guys ,I'M new To Magento ??

2 Answers 2

2

This is answer to my own question.i have done it.i kept my this coding in list.phtml as posted in question:

<?php
    $_categories = Mage::getModel('catalog/category')->getCollection()
    ->addAttributeToSelect('*')
    ->addAttributeToFilter('is_active', 1);       

    foreach ($_categories as $_category)
        {  
            if($_category->getImageUrl())  
                {  
                    $catimg     = $_category->getImageUrl();  
?>
<div class="category1">  
<img src="<?php echo $catimg ;?>" alt="" />
  <a class="cate_btn" title="View the products for this category" href="<?php echo $_category->getUrl($_category) ;?>">View</a>
  </div> 

<?php } } ?>

I just drag all categories to default category:like this

enter image description here

with this url is changed as following.and it worked.

rtd/index.php/cat1.html

0
1

You have to do "catalog url rewriting " reindex and clear the cache.

10
  • can you explain your answer ,why and how can we do this in backend in magento.? Commented Sep 11, 2014 at 10:39
  • jigesh..I reindex catalog urls and cleared the cache.but same result. Commented Sep 11, 2014 at 10:58
  • <?php $_helper= Mage::helper('catalog/category') ?> <?php $_categories = Mage::getModel('catalog/category')->getCollection() ->addAttributeToSelect('name') ->addAttributeToSelect('is_active'); ?> <?php foreach($_categories as $_category): ?> </br> <a href="<?php echo $_helper->getCategoryUrl($_category); ?>"> <?php echo$_category->getName() ?> </a> <?php endforeach;?>
    – Jignesh
    Commented Sep 11, 2014 at 11:12
  • try above code and give me the results.
    – Jignesh
    Commented Sep 11, 2014 at 11:12
  • 1
    catalog/category/view/s/cat1/id/3/ this will not work at all. because the main or default category we can not show on the page. only product listing we can see. if your trying to show the default or main category or with its subcategory than you have to customize the coding.
    – Jignesh
    Commented Sep 11, 2014 at 11:14

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.