Magento – Trying to get Category URL in Home

magento-1.9widgets

I'm trying to get the Category URL in my Home page, I'm working in the file app/design/fronted/[package]/[theme]/template/catalog/product/widget/new/content/new_grid.phtml

I've got this code above the product title

<?php
/**
 * get categories from a product
 */
$categoryIds = $this->helper('catalog/output')->productAttribute($_product, $_product->getCategoryIds());
/**
 * looping through the array of category ids
 */
foreach($categoryIds as $categoryId) {
    $category = Mage::getModel('catalog/category')->load($categoryId);
    if($category->parent_id == 4):
?>
    <h6 class="author"><a href="<?php echo $category->getUrlKey() ?>">De <?php echo $category->getName() ?></a></h6>
<?php
    endif;
}
?>

Some times I use "getUrl" instead of "getUrlKey", and both give me a "404" page.
I believe the error is in some Magento configuration, not in the code.

Some one have an answer to any approach?

Thanks in advence!

Best Answer

Re-index everything and especially make sure that Catalog URL Rewrites is up to date.

Also check mod_rewrite to ensure that it is enabled. You can tell if this is the problem when you have SEO Friendly URLs turned on but still need to put index.php in the URL.

Related Topic