Joomla(Virtuemart) & php

Discussion in 'PHP' started by Kandi, 19 Oct 2011.

  1. Kandi

    Kandi Member

    Joined:
    18 Nov 2009
    Messages:
    344
    Likes Received:
    17
    Reputations:
    0
    Всем привет) вот хочу попросить помощи в php, а точнее в движке joomla. Собственно нужно сделать вывод категорий типа:
    Code:
    <ul id="menu">
        <li><a href="#">Category 1</a>
            <ul>
                <li><a href="#">Subitem 1</a></li>
                <li><a href="#">Subitem 2</a></li>
                <li><a href="#">Subitem 3</a></li>
            </ul>
        </li>
        <li><a href="#">Category 2</a>
            <ul>
                <li><a href="#">Subitem 1</a></li>
                <li><a href="#">Subitem 2</a></li>
            </ul>
        </li>
    </ul>
    
    Вот нашёл файл по пути - www\administrator\components\com_virtuemart\classes\ps_product_category.php

    Он то по-моему за всё это и отвечает т.к. нашёл такой кусочек кода:
    Code:
    	function get_category_tree( $category_id=0,
    				$links_css_class="mainlevel",
    				$list_css_class="mm123",
    				$highlighted_style="font-style:italic;" ) {
    		global $sess;
    
    		$categories = ps_product_category::getCategoryTreeArray(); // Get array of category objects
    		$result = ps_product_category::sortCategoryTreeArray($categories); // Sort array of category objects
    		$row_list = $result['row_list'];
    		$depth_list = $result['depth_list'];
    		$category_tmp = $result['category_tmp'];
    		$nrows = sizeof($category_tmp);
    
    		// Copy the Array into an Array with auto_incrementing Indexes
    		$key = array_keys($categories); // Array of category table primary keys
    		
    		$nrows = $size = sizeOf($key); // Category count
    
    		$html = "";
    
    		// Find out if we have subcategories to display
    		$allowed_subcategories = Array();
    		if( !empty( $categories[$category_id]["category_parent_id"] ) ) {
    			// Find the Root Category of this category
    			$root = $categories[$category_id];
    			$allowed_subcategories[] = $categories[$category_id]["category_parent_id"];
    			// Loop through the Tree up to the root
    			while( !empty( $root["category_parent_id"] )) {
    				$allowed_subcategories[] = $categories[$root["category_child_id"]]["category_child_id"];
    				$root = $categories[$root["category_parent_id"]];
    			}
    		}
    		// Fix the empty Array Fields
    		if( $nrows < count( $row_list ) ) {
    			$nrows = count( $row_list );
    		}
    
    		// Now show the categories
    		$html .= '<div class="vmMenuCategories">';
    		for($n = 0 ; $n < $nrows ; $n++) {
    
    			if( !isset( $row_list[$n] ) || !isset( $category_tmp[$row_list[$n]]["category_child_id"] ) )
    			continue;
    			if( $category_id == $category_tmp[$row_list[$n]]["category_child_id"] )
    			$style = $highlighted_style;
    			else
    			$style = "";
    
    			$allowed = false;
    			if( $depth_list[$n] > 0 ) {
    				// Subcategory!
    				if( isset( $root ) && in_array( $category_tmp[$row_list[$n]]["category_child_id"], $allowed_subcategories )
    				|| $category_tmp[$row_list[$n]]["category_parent_id"] == $category_id
    				|| $category_tmp[$row_list[$n]]["category_parent_id"] == @$categories[$category_id]["category_parent_id"]) {
    					$allowed = true;
    
    				}
    			}
    			else
    			$allowed = true;
    			$append = "";
    			if( $allowed ) {
    				if( $style == $highlighted_style ) {
    					$append = 'id="active_menu"';
    				}
    				if( $depth_list[$n] > 0 ) {
    					$css_class = "sublevel";
    				}
    				else {
    					$css_class = $links_css_class;
    				}
    
    				$catname = shopMakeHtmlSafe( $category_tmp[$row_list[$n]]["category_name"] );
    
    				$html .= '
              <a title="'.$catname.'" style="display:block;'.$style.'" class="'. $css_class .'" href="'. $sess->url(URL."index.php?page=shop.browse&amp;category_id=".$category_tmp[$row_list[$n]]["category_child_id"]) .'" '.$append.'>'
    				. str_repeat("&nbsp;&nbsp;&nbsp;",$depth_list[$n]) . $catname
    				. ps_product_category::products_in_category( $category_tmp[$row_list[$n]]["category_child_id"] )
    				.'</a>';
    			}
    		}
    
    Но вот он выводит меню типа:
    Code:
    <div id="menu">
       <a href="#">Category 1</a>
       <a href="#">Category 2</a>
       <a href="#">Category 3</a>
    </div>
    
    Как переделать его подскажите пожалуйста кому не влом :rolleyes:

    P.S. В php почти алёшка подай патроны :D
     
  2. Andres

    Andres Elder - Старейшина

    Joined:
    4 Apr 2008
    Messages:
    320
    Likes Received:
    119
    Reputations:
    0
    Нихрена не понял
    Ты хочешь каждую категорию циклом выводить?
     
  3. Kandi

    Kandi Member

    Joined:
    18 Nov 2009
    Messages:
    344
    Likes Received:
    17
    Reputations:
    0
    Ну функция выводит категории мне бы переделать функцию, чтобы она обращалась к базе и выводила категории и подкатегории у меня всего 3 категории и у каждой по 5-10 подкатегорий, вот хочу чтобы выводилось так, а потом замутить что нить с jQuery, по этому и прошу помощи)
     
    #3 Kandi, 19 Oct 2011
    Last edited: 20 Oct 2011
  4. Andres

    Andres Elder - Старейшина

    Joined:
    4 Apr 2008
    Messages:
    320
    Likes Received:
    119
    Reputations:
    0
    Для вывода категорий и подкатегорий:
    Code:
    <?php if( !defined( '_VALID_MOS' ) && !defined( '_JEXEC' ) ) die( 'Direct Access to '.basename(__FILE__).' is not allowed.' ); 
    mm_showMyFileName(__FILE__);
     
    $iCol = 1;
    if( !isset( $categories_per_row )) {
    	$categories_per_row = 3;
    }
    $cellwidth = intval( 100 / $categories_per_row );
     
    if( empty( $categories )) {
    	return; // Do nothing, if there are no child categories!
    }
    ?>
    <br/>
     
     
    <table width="100%" cellspacing="0" cellpadding="0">
    <?php
    foreach( $categories as $category ) {
    	if ($iCol == 1) { // this is an indicator wether a row needs to be opened or not
    		echo "<tr>\n";
    	}
    	?>	
     
    	<td valign="top" align="center" width="<?php echo $cellwidth ?>%" >
    		<br />
             <p><a title="<?php echo $category["category_name"] ?>" href="<?php $sess->purl(URL."index.php?option=com_VirtueMart&amp;page=shop.browse&amp;category_id=".$category["category_id"]) ?>"> 
    			<?php
    			if ( $category["category_thumb_image"] ) {
    				echo ps_product::image_tag( $category["category_thumb_image"], "alt=\"".$category["category_name"]."\"", 0, "category");
    				echo "<br /><br/>\n";
    			}
    			echo $category["category_name"];
    			echo $category['number_of_products'];
    			?>
    		 </a></p>
    		 <div align="left" style="padding-left:5px;"> <a title="<?php echo $category["category_name"] ?>" href="<?php echo $sess->url(URL."index.php?option=com_VirtueMart&amp;page=shop.browse&amp;category_id=".$category["category_id"]); ?>"> 
       <?php    echo ps_product_category::get_subcategory ( $category["category_id"] );
       ?>
       </a></div>
    	</td>
    	<?php
    	// Do we need to close the current row now?
    	if ($iCol == $categories_per_row) { // If the number of products per row has been reached
    		echo "</tr>\n";
    		$iCol = 1;
    	}
    	else {
    		$iCol++;
    	}
    }
    // Do we need a final closing row tag?
    if ($iCol != 1) {
    	echo "</tr>\n";
    }
    ?>	
    	</table>
    
    categoryChildlist.tpl - файл
     
  5. Kandi

    Kandi Member

    Joined:
    18 Nov 2009
    Messages:
    344
    Likes Received:
    17
    Reputations:
    0
    я в курсе, но этот файл выводи на главной странице название категорий в них подкатегории с картинками, а мне нужны те категории и подкатегории которые как бы МЕНЮ))))) virtuemart