0

I have a store that I am developing using Magento CE 1.8.1. On my category pages, I have modified the 2 Column Left Sidebar but I am having an issue.

On the left side bar, I have made a border via css where it shows subcategories, prices, etc. This same border will appear with nothing in it when a category does not have any sub categories.

How would I make no border appear when the category does not have any sub-categories?

<div class="wrapper">
<?php echo $this->getChildHtml('global_notices') ?>
    <?php echo $this->getChildHtml('header') ?>
    <div class="container thirteen columns">
        <div class="main">
            <?php echo $this->getChildHtml('breadcrumbs') ?>
             <aside class="col-left sidebar three columns"><?php echo $this->getChildHtml('left') ?></aside>
            <section class="col-main twelve columns">
                <?php echo $this->getChildHtml('global_messages') ?>
                <?php echo $this->getChildHtml('content') ?>
            </section>
        </div>
    </div>
    <?php echo $this->getChildHtml('footer') ?>
    <?php echo $this->getChildHtml('global_cookie_notice') ?>
    <?php echo $this->getChildHtml('before_body_end') ?>
</div>
<?php echo $this->getAbsoluteFooter() ?>

Basically, I am using the 2column-left template and copied into my theme directory. Above, I have where it says aside class="col-left sidebar three columns", my css looks like the following:

aside.col-left
{
    border: 1px dotted #000;
    border-right-width: thin;
    padding: 7px 5px 10px 5px;
} 

I am still new to developing for magento so maybe I am doing it wrong. Any pointers would help?

  • Could you show use you template file. Thanks. – David Manners Jan 7 '14 at 6:08
  • It will be a blind guess work if you don't provide your markup, so post your template for a clear answer. – Shathish Jan 7 '14 at 11:24
  • Probably before the foreach loop and the div which contains the subcategories you will have to check if there are subcategories at all. But better show us the template code. – enenen Jan 7 '14 at 11:55
1

There is some another way. Using this code you can easily more clear which is parent category and which one sub-category so just you have to add your class in first loop. In my code there is done using ul li tag instead of you can set the div tag.

<?php $_helper = Mage::helper('catalog/category') ?>
<?php $_categories = $_helper->getStoreCategories() ?>
<?php $currentCategory = Mage::registry('current_category') ?>
<?php if (count($_categories) > 0): ?>
    <ul id="nav">
           <?php foreach($_categories as $_category): ?>
        <li>
            <a href="<?php echo $_helper->getCategoryUrl($_category) ?>">
                <?php echo $_category->getName() ?>
            </a>
            <?php $_category = Mage::getModel('catalog/category')->load($_category->getId()) ?>
            <?php $_subcategories = $_category->getChildrenCategories() ?>
            <?php if (count($_subcategories) > 0): ?>
                <ul>
                    <?php foreach($_subcategories as $_subcategory): ?>
                        <li>
                            <a href="<?php echo $_helper->getCategoryUrl($_subcategory) ?>">
                                <?php echo $_subcategory->getName() ?>
                            </a>
                        </li>
                    <?php endforeach; ?>
                </ul>
            <?php endif; ?>
            </li>
        <?php endforeach; ?>
    </ul>
<?php endif; ?>
  • Your code did help me alot even though I need to tweak a little bit to fit my design. – barakisbrown Jan 7 '14 at 22:14
  • Thanks a lot ya that y I mention you have to change code as your div tag and write css for that – Keyul Shah Jan 8 '14 at 3:33
2

You can add a if condition in your loop as following:

$category = Mage::getModel('catalog/category')->load($id);
$count = count($category->getChildren());
if($count == 0) {
   --Display div without border--
} else {
   --Display div with border--
}

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.