Jean Linux
Jean Linux

Reputation: 237

Magento How do i add "Home" link accross magento multi store site that shares same theme

I have a magento website with multi store and i have been able to add the home link on the default store. the whole site along with its multi stores shares the same theme but in the theme i edited template/page/navigation/top.php with the code

<?php 
$_anyActive = false; 

foreach ($this->getStoreCategories() as $_category) 
{ 
   $_anyActive = $_anyActive || $this->isCategoryActive($_category); 
} 
?>

<li class="home <?php echo !$_anyActive ? 'active' : '' ?>">
    <a href="<?php echo $this->getUrl('')?>"><span><?php echo $this->__('Home') ?></span></a>
</li>

This code now makes the home link shows but now its only shows in the default store but i want it to show in all other stores, i dont understand this but as they whole stores shares the same theme, i thought maybe they should also be able to read this code and display the home link, i could duplicate the themes and then assign them to each store (which i'm not even sure would work) but that would make the code deficult to maintain as i though if they share the same design, i could just make one change and reflect on the entire sub stores.

The following is the content of template/page/navigation/top.php

    <?php $_menu = ''?>
    <?php foreach ($this->getStoreCategories() as $_category): ?>
    <?php $_menu .= $this->drawItem($_category) ?>
    <?php endforeach ?>
    <?php if ($_menu): ?>
    <div class="nav-container">
    <ul id="nav">

    <?php $_anyActive = false; foreach ($this->getStoreCategories() as $_category)         { $_anyActive = $_anyActive || $this->isCategoryActive($_category); } ?>
     <li class="home <?php echo !$_anyActive ? 'active' : '' ?>"><a href="<?php echo $this->getUrl('')?>"><span><?php echo $this->__('Home') ?></span></a></li> 

    <?php echo $_menu; ?>
</ul>
     </div>
    <?php endif; ?>

I hope you are able to help me solve this problem

Upvotes: 1

Views: 1576

Answers (3)

adprocas
adprocas

Reputation: 1913

Neeraj Garg's answer was the solution in the end, but I wanted to expand on it.

Go to /app/design/frontend/default/yourtheme/template/page/html/topmenu.phtml

That might be specific to my theme. I think most would be using top.phtml in a different folder, as mentioned in the question. Turn on Template Path Hints in the System->Configuration->Advanced->Developer section (you may need to change your scope) to find out what file your navigation menu can be edited in. Make sure you copy and paste it outside of your base theme into your current theme, if it is using the base theme.

After that, I used a similar solution to Neeraj's suggestion. Mine looks like this, and is obviously dependent on the theme I am using (yours will likely look much different, as it will likely need to be catered to your theme).

<li class="level0 nav-0 first level-top <?php if (Mage::helper('core/url')->getCurrentUrl() === Mage::helper('core/url')->getHomeUrl()):?> active<?php endif;?>">
    <a href="\" class="level-top">
        <span>Home</span>
    </a>
</li>
<?php echo $_menu ?>

Upvotes: 0

Neeraj Garg
Neeraj Garg

Reputation: 705

Use following code

<li class="home <?php if (Mage::helper('core/url')->getCurrentUrl() === Mage::helper('core/url')->getHomeUrl()):?> active<?php endif;?>"><a href="<?php echo $this->getUrl('')?>"><span><?php echo $this->__('Home') ?></span></a></li>

Upvotes: 1

Tim Bezhashvyly
Tim Bezhashvyly

Reputation: 9100

I guess the problem is that you put your home link inside of main navigation. As your secondary stores don't have any navigation, the whole unordered list has not been generated.

Try this:

<?php

 $_menu = '';
 $_anyActive = false;
 foreach ($this->getStoreCategories() as $_category){
  $_menu .= $this->drawItem($_category);
  $_anyActive = $_anyActive || $this->isCategoryActive($_category);
 }

?>

<div class="nav-container">
<ul id="nav">
 <li class="home <?php echo !$_anyActive ? 'active' : '' ?>"><a href="<?php echo $this->getUrl('')?>"><span><?php echo $this->__('Home') ?></span></a></li>
 <?php echo $_menu; ?>
</ul>
</div>

Upvotes: 0

Related Questions