How can I check in a template file if a category with a certain ID exists, eg. ID 270.

I have tried the following but the statement is echoed even though there is no category 270. I'm not really sure what else to try... thanks very much for any help!

$category = new Mage_Catalog_Model_Category();

if ($category->load(270)) {         
    echo "Category found";
$category = Mage::getModel('catalog/category')->load(270);
if($category->getId()) {
    echo "Category found";

You can check this by following code:

    $_category = Mage::getModel('catalog/category')->load(270);
    if($_category->getId()) {
        echo "Category found";
    } else {
        echo "Category not found";

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.