Доброе время суток помогите с функцией.
надо чтобы эта функция
формировала такие же ссылки как эта:
для удобной навигации нужно переделать
внутри search.php стоит следующий код, тот что вызывает
надо чтобы эта функция
Код:
/*subcategories name search */
if( !function_exists('get_categoriesOlx') ) {
function get_categoriesOlx( ) {
$location = Rewrite::newInstance()->get_location() ;
$section = Rewrite::newInstance()->get_section() ;
if ( $location != 'search' ) {
return false ;
}
$category_id = osc_search_category_id() ;
if(count($category_id) > 1) {
return false;
}
$category_id = (int) $category_id ;
$categoriesOlx = Category::newInstance()->hierarchy($category_id) ;
foreach($categoriesOlx as &$category) {
$category['url'] = get_category_url($category) ;
}
return $categoriesOlx ;
}
}
if( !function_exists('get_subcategories') ) {
function get_subcategories( ) {
$location = Rewrite::newInstance()->get_location() ;
$section = Rewrite::newInstance()->get_section() ;
if ( $location != 'search' ) {
return false ;
}
$category_id = osc_search_category_id() ;
if(count($category_id) > 1) {
return false ;
}
$category_id = (int) $category_id[0] ;
$subCategories = Category::newInstance()->findSubcategories($category_id) ;
foreach($subCategories as &$category) {
$category['url'] = get_category_url($category) ;
}
return $subCategories ;
}
}
if ( !function_exists('get_category_url') ) {
function get_category_url( $category ) {
$path = '';
if ( osc_rewrite_enabled() ) {
if ($category != '') {
$category = Category::newInstance()->hierarchy($category['pk_i_id']) ;
$sanitized_category = "" ;
for ($i = count($category); $i > 0; $i--) {
$sanitized_category .= $category[$i - 1]['s_slug'] . '/' ;
}
$path = osc_base_url() . $sanitized_category ;
}
} else {
$path = sprintf( osc_base_url(true) . '?page=search&sCategory=%d', $category['pk_i_id'] ) ;
}
return $path;
}
}
if ( !function_exists('get_category_num_items') ) {
function get_category_num_items( $category ) {
$category_stats = CategoryStats::newInstance()->countItemsFromCategory($category['pk_i_id']) ;
if( empty($category_stats) ) {
return 0 ;
}
return $category_stats;
}
}
формировала такие же ссылки как эта:
Код:
function osclasswizards_sidebar_category_search($catId = null)
{
$aCategories = array();
if($catId==null) {
$aCategories[] = Category::newInstance()->findRootCategoriesEnabled();
} else {
// if parent category, only show parent categories
$aCategories = Category::newInstance()->toRootTree($catId);
end($aCategories);
$cat = current($aCategories);
// if is parent of some category
$childCategories = Category::newInstance()->findSubcategoriesEnabled($cat['pk_i_id']);
if(count($childCategories) > 0) {
$aCategories[] = $childCategories;
}
}
if(count($aCategories) == 0) {
return "";
}
osclasswizards_print_sidebar_category_search($aCategories, $catId);
}
function osclasswizards_print_sidebar_category_search($aCategories, $current_category = null, $i = 0)
{
$class = '';
if(!isset($aCategories[$i])) {
return null;
}
if($i===0) {
$class = 'class="category"';
}
$c = $aCategories[$i];
$i++;
if(!isset($c['pk_i_id'])) {
echo '<ul '.$class.'>';
if($i==1) {
echo '<li><a href="'.osc_esc_html(osc_update_search_url(array('sCategory'=>null, 'iPage'=>null))).'">'.__('All categories', OSCLASSWIZARDS_THEME_FOLDER)."</a></li>";
}
foreach($c as $key => $value) {
?>
<li> <a id="cat_<?php echo osc_esc_html($value['pk_i_id']);?>" href="<?php echo osc_esc_html(osc_update_search_url(array('sCategory'=> $value['pk_i_id'], 'iPage'=>null))); ?>">
<?php if(isset($current_category) && $current_category == $value['pk_i_id']){ echo '<strong>'.$value['s_name'].'</strong>'; }
else{ echo $value['s_name']; } ?>
</a> </li>
<?php
}
if($i==1) {
echo "</ul>";
} else {
echo "</ul>";
}
} else {
?>
<ul <?php echo $class;?>>
<?php if($i==1) { ?>
<li><a href="<?php echo osc_esc_html(osc_update_search_url(array('sCategory'=>null, 'iPage'=>null))); ?>">
<?php _e('All categories', OSCLASSWIZARDS_THEME_FOLDER); ?>
</a></li>
<?php } ?>
<li> <a id="cat_<?php echo osc_esc_html($c['pk_i_id']);?>" href="<?php echo osc_esc_html(osc_update_search_url(array('sCategory'=> $c['pk_i_id'], 'iPage'=>null))); ?>">
<?php if(isset($current_category) && $current_category == $c['pk_i_id']){ echo '<strong>'.$c['s_name'].'</strong>'; }
else{ echo $c['s_name']; } ?>
</a>
<?php osclasswizards_print_sidebar_category_search($aCategories, $current_category, $i); ?>
</li>
<?php if($i==1) { ?>
<?php } ?>
</ul>
<?php
}
}
для удобной навигации нужно переделать
внутри search.php стоит следующий код, тот что вызывает
Код:
<div class="subcateg_list">
<?php $spubcat = get_categoriesOlx(); ?>
<?php if (!isset($spubcat[2]) && !isset($spubcat[1]) && isset($spubcat[0])) { ?>
<?php ;
foreach(get_subcategories() as $subcat) {
echo "<li><span><a href='".$subcat["url"]."'><span>".$subcat["s_name"]."</span></a> <span class='color'>" . get_category_num_items($subcat) . "</span></span></li>";
} }?>
</div>