2014-06-06 51 views
1

我試圖動態地將製造商添加到下拉菜單中,我寫了一條foreach語句,但沒有任何內容顯示在首頁上。OpenCart Manufactures DropDown

任何人都可以檢查代碼,並擺脫一些光線,將不勝感激的幫助。

<?php if ($categories) { ?> 
<div id="menu-holder" class="<?php echo (isset($styler['menu_style']) && ($styler['menu_style']!='')) ? $styler['menu_style']."_menu" : '' ;?>"> 
<div id="menu"> 
    <ul> 
     <li><a href="<?php echo $home; ?>"><span class='home_icon'></span></a> 
    <?php foreach ($categories as $category) { ?> 
    <li><a href="<?php echo $category['href']; ?>"><?php echo $category['name']; ?><?php if ($category['children']) { ?><span></span><?php } ?></a> 
     <?php if ($category['children']) { ?> 
     <div> 
     <?php for ($i = 0; $i < count($category['children']);) { ?> 
     <ul> 
      <?php $j = $i + ceil(count($category['children'])/$category['column']); ?> 
      <?php for (; $i < $j; $i++) { ?> 
      <?php if (isset($category['children'][$i])) { ?> 
      <li><a<?php echo ($i==(count($category['children'])-1) ? " class='last_submenu_item'" : '');?> href="<?php echo $category['children'][$i]['href']; ?>"><span><?php echo $category['children'][$i]['name']; ?></span></a></li> 
      <?php } ?> 
      <?php } ?> 
     </ul> 
     <?php } ?> 
     </div> 
     <?php } ?> 
    </li> 
    <?php } ?> 
    </ul> 
    <ul> 
    <?php foreach ($manufacturers as $manufacturer) { ?> 
    <li><a href="<?php echo $manufacturer['href']; ?>"><?php echo $manufacturer['name']; ?></a></li> 
    <?php } ?> 
    </ul> 
    <ul> 
<li><a href="#">Football Clubs</a></li> 
    </ul> 

</div> 
</div> 
<?php } ?> 
+0

請給出你的輸出的例子HTML – vico

+0

這是上面的代碼的輸出,應該有一個額外的鏈接箭頭指向:http://i59.tinypic.com/90ynmc.png –

+0

讓我知道如果你們需要任何東西來幫助我這個:) –

回答

0

按照以下4個步驟&在您的網站添加下面4個步驟的代碼&然後檢查。

步驟1

替換下面的代碼,而不是你的代碼。

<?php if ($categories) { ?> 
<div id="menu-holder" class="<?php echo (isset($styler['menu_style']) && ($styler['menu_style']!='')) ? $styler['menu_style']."_menu" : '' ;?>"> 
<div id="menu"> 
    <ul> 
     <li><a href="<?php echo $home; ?>"><span class='home_icon'></span></a></li> 
    <?php foreach ($categories as $category) { ?> 
    <li><a href="<?php echo $category['href']; ?>"><?php echo $category['name']; ?><?php if ($category['children']) { ?><span></span><?php } ?></a> 
     <?php if ($category['children']) { ?> 
     <div> 
     <?php for ($i = 0; $i < count($category['children']);) { ?> 
     <ul> 
      <?php $j = $i + ceil(count($category['children'])/$category['column']); ?> 
      <?php for (; $i < $j; $i++) { ?> 
      <?php if (isset($category['children'][$i])) { ?> 
      <li><a<?php echo ($i==(count($category['children'])-1) ? " class='last_submenu_item'" : '');?> href="<?php echo $category['children'][$i]['href']; ?>"><span><?php echo $category['children'][$i]['name']; ?></span></a></li> 
      <?php } ?> 
      <?php } ?> 
     </ul> 
     <?php } ?> 
     </div> 
     <?php } ?> 
    </li> 
    <?php } ?> 
    <li><a href="<?php echo $manufacturer; ?>"><?php echo $text_manufacturer; ?></a> 
     <div> 
     <ul> 
     <?php foreach ($manufacturers as $manufacturer) { ?> 
    <li><a href="<?php echo $manufacturer['href']; ?>"><?php echo $manufacturer['name']; ?></a></li> 
    <?php } ?> 
    </ul> 
    </div> 
    </li> 
    <li><a href="#">Football Clubs</a></li> 
    </ul> 
</div> 
</div> 
<?php } ?> 



步驟2

轉到源>目錄>控制器>常見> &然後打開「的header.php」文件。

查找:

$this->data['text_checkout'] = $this->language->get('text_checkout'); 

後添加:

$this->data['text_manufacturer'] = $this->language->get('text_manufacturer'); 



步驟3

去源>目錄>控制器>通用> &然後打開「header.php」文件。

查找:

$this->data['checkout'] = $this->url->link('checkout/checkout', '', 'SSL'); 

後添加:

$this->data['manufacturer'] = $this->url->link('product/manufacturer'); 



步驟4

去你的來源>目錄>控制器>通用> &然後打開「header.php」文件。

查找:

$this->load->model('catalog/product'); 

後添加:

$this->load->model('catalog/manufacturer'); 
    $this->load->model('tool/image'); 
    $results = $this->model_catalog_manufacturer->getManufacturers(); 
    foreach ($results as $result) { 
     $this->data['manufacturers'][] = array(
      'name' => $result['name'], 
      'href' => $this->url->link('product/manufacturer/info', 'manufacturer_id=' . $result['manufacturer_id']) 
     ); 
    } 


&然後檢查它。

+0

完美的工作,所以我所缺少的是語言和模塊在控制器部分... –

0

嘗試print_r你的數組只是確保你指向正確的地方的東西。

我注意到的一些代碼,你可能想看看。

if ($category['children']) { ?><span></span><?php } 

李家沒有結束標籤)計數範圍內

<li><a href="<?php echo $home; ?>"><span class='home_icon'></span></a></li> 

分號(

for ($i = 0; $i < count($category['children']);) { 

應該在PHP構建爲一個字符串,然後輸出和使用的foreach循環,而不是一切將防止更少的錯誤