2010-09-18 2 views
2

Во-первых, я новичок в Magento, поэтому, пожалуйста, объясните подробно, если вы можете помочь.Список категорий, не работающих на странице категории - Magento

Я использовал следующий код:

<div class="left-nav-inner"> 
    <h3 id="products">Products</h3> 
    <h4>Shop by:</h4> 
    <ul id="product-menu"> 

<?php 
/* Get the categories that are active for the store */ 
$_main_categories=$this->getStoreCategories(); 

/* Get the current category the user is in */ 
$_current_category=$this->getCurrentCategory(); 

/* Get the current category path */ 
$_categorypath = $this->getCurrentCategoryPath(); 
?> 
<?php 
if ($_main_categories): 
    /* This bit cycles through the categories - setting the next one to current */ 
    foreach ($_main_categories as $_main_category): 
     if($_main_category->getIsActive()):        
      $cur_category=Mage::getModel('catalog/category')->load($_main_category->getId()); 
      $layer = Mage::getSingleton('catalog/layer'); 
      $layer->setCurrentCategory($cur_category);  

/* Write the main categories */   
?>     
<li><a href="<?php echo $this->getCurrentCategory()->getUrl()?>"><?php echo $this->getCurrentCategory()->getName();?></a></li> 


<?php 

/* Check the category variable loop against the current category path if it is - print sub categories */ 
if (in_array($this->getCurrentCategory()->getId(), $_categorypath)): ?> 
<?php $_maincategorylisting=$this->getCurrentCategory()?>       
<?php $_categories=$this->getCurrentChildCategories()?> 
<?php if($_categories->count()):?> 


<?php /* This resets the category back to the original pages category 
****  If this is not done, subsequent calls on the same page will use the last category 
**** in the foreach loop 
*/ ?> 
<?php $layer->setCurrentCategory($_current_category); ?> 
<?php endif; ?> 

<?php endif; ?>         

<?php   
endif; 
endforeach; 
else: 
?> 
<p>$_main_categories array was empty.</p> 
<p>This might be because you are referencing this phtml file with a wrong type attribute. You should use <block type="catalog/navigation" ... /> !</p> 
<?php endif; ?> 
</div> 

Это отображает списки на левом меню, как требуется, однако, когда я нажимаю категорию URLS страница категории не будет показывать продукты ..

Я получить продукты, чтобы показать, если удалить левый столбец в:

приложение/дизайн/интерфейс/по умолчанию/по умолчанию/макет/catalog.xml

я сделал это с помощью следующего кода:


Категория размещения по умолчанию


<catalog_category_default translate="label"> 
    <label>Catalog Category (Non-Anchor)</label> 
    <remove name="left" /> 

Как вы можете видеть, что я добавил "удалить имя = левый.

мне нужно иметь левое меню с категориями отображаются на каждой странице сайта, и мне нужны продукты, чтобы показать, когда я нажимаю на категории ...

Пожалуйста, помогите.

+0

Что отображается на целевом URL? Вы получаете стандартный верхний/нижний колонтитул и без содержания? Получаете ли вы название категории и cms-блок и нет лимента продукта? Вы проверили, что ведение журнала включено, и для записей в файле system.log и/или exception.log? –

+0

Я получаю все, кроме продуктов. Заголовок категории отображается правильно, вместе с панировкой и т. Д. Он отлично работает, показывая все продукты, когда я не использую левый навигатор. Так что что-то в коде списка категорий отбрасывает, я думаю –

ответ

0

Похоже, вам не хватает тега </ul> после вашего endforeach.

Взгляните в ваш источник html. Вы можете обнаружить, что все находится на странице, просто вложенной в тег <ul>, поэтому браузер не получает визуализацию.

Если я прав, Это должно показать вещи для вас (обратите внимание на </ul> тег ближе к концу):

<div class="left-nav-inner"> 
    <h3 id="products">Products</h3> 
    <h4>Shop by:</h4> 
    <ul id="product-menu"> 

<?php 
/* Get the categories that are active for the store */ 
$_main_categories=$this->getStoreCategories(); 

/* Get the current category the user is in */ 
$_current_category=$this->getCurrentCategory(); 

/* Get the current category path */ 
$_categorypath = $this->getCurrentCategoryPath(); 
?> 
<?php 
if ($_main_categories): 
    /* This bit cycles through the categories - setting the next one to current */ 
    foreach ($_main_categories as $_main_category): 
     if($_main_category->getIsActive()):        
      $cur_category=Mage::getModel('catalog/category')->load($_main_category->getId()); 
      $layer = Mage::getSingleton('catalog/layer'); 
      $layer->setCurrentCategory($cur_category);  

/* Write the main categories */   
?>     
<li><a href="<?php echo $this->getCurrentCategory()->getUrl()?>"><?php echo $this->getCurrentCategory()->getName();?></a></li> 


<?php 

/* Check the category variable loop against the current category path if it is - print sub categories */ 
if (in_array($this->getCurrentCategory()->getId(), $_categorypath)): ?> 
<?php $_maincategorylisting=$this->getCurrentCategory()?>       
<?php $_categories=$this->getCurrentChildCategories()?> 
<?php if($_categories->count()):?> 


<?php /* This resets the category back to the original pages category 
****  If this is not done, subsequent calls on the same page will use the last category 
**** in the foreach loop 
*/ ?> 
<?php $layer->setCurrentCategory($_current_category); ?> 
<?php endif; ?> 

<?php endif; ?>         

<?php   
endif; 
endforeach; 
?> 
</ul><!-- See what I did here? --> 
<?php 
else: 
?> 

<p>$_main_categories array was empty.</p> 
<p>This might be because you are referencing this phtml file with a wrong type attribute. You should use <block type="catalog/navigation" ... /> !</p> 
<?php endif; ?> 
</div> 
0

Я бы порекомендовал вам использовать Layoutviewer от Alan Storm для отладки того, что происходит на вашем целевом URL-адресе. Вы можете скачать его с this article, обратите внимание, что вам нужно будет создать свою собственную декларацию модуля xml для вставки в app/etc/modules для активируемого модуля.

0

Перейти к Администратор -> CMS-> pages-> Главная PAGE- > design-> custom design -> Добавить этот код

<reference name="left"> 
    <block type="catalog/navigation" name="catalog.leftnav" after="currency" template="catalog/navigation/left.phtml"/> 
</reference> 
Смежные вопросы