Revise search by subcategory
From OSClass
This customization will enable search results to be refined by a subcategory (works using most OSClass themes).
By default, from the homepage if you click on a Category, it will take you to the "Search" page and display that category with a check-box next to it along the left-hand menu. However, if you click on a subcategory, no subcategory is displayed on the search page in that same side menu.
This customization will enable subcategories to be shown on the search page when clicked-on from the homepage. This will allow users to refine their search based on that subcategory alone. This works with either permalinks enabled or disabled.
Below is screen-shot of what this customization will do. In this example, there are two parent categories, Cars and Planes. Cars has several subcategories, including one called Ford. Here, the user has clicked on the subcategory Ford from the homepage and taken to the search page:
To make this change, first locate the following code within the theme file search.php:
<?php osc_get_non_empty_categories(); ?>
<?php if ( osc_count_categories() ) { ?>
<div class="row checkboxes">
<h6><?php _e('Category', 'bcute') ; ?></h6>
<ul>
<?php // RESET CATEGORIES IF WE USED THEN IN THE HEADER ?>
<?php osc_goto_first_category() ; ?>
<?php while(osc_has_categories()) { ?>
<li>
<input type="checkbox" id="cat<?php echo osc_category_id(); ?>" name="sCategory[]" value="<?php echo osc_category_id(); ?>" <?php echo ( (in_array(osc_category_id(), osc_search_category()) || in_array(osc_category_slug()."/", osc_search_category()) || count(osc_search_category())==0 ) ? 'checked' : '') ; ?> /> <label for="cat<?php echo osc_category_id(); ?>"><strong><?php echo osc_category_name(); ?></strong></label>
</li>
<?php } ?>
</ul>
</div>
<?php } ?>
And replace it with this code:
<?php osc_get_non_empty_categories(); ?>
<?php
$sCategory = Params::getParam('sCategory'); $sCategory2 = Params::getParam('sCategory[]');
if(osc_rewrite_enabled()) {
$URL = $_SERVER['REQUEST_URI'];
$directory = pathinfo($URL);
$category = $directory['filename'];
}
?>
<?php if ( osc_count_categories()) { ?>
<div class="row checkboxes">
<h6><?php _e('Category', 'bcute') ; ?></h6>
<ul>
<?php // RESET CATEGORIES IF WE USED THEN IN THE HEADER ?>
<?php osc_goto_first_category() ; ?>
<?php while(osc_has_categories()) { ?>
<li>
<input type="checkbox" id="cat<?php echo osc_category_id(); ?>" name="sCategory[]" value="<?php echo osc_category_id(); ?>" <?php echo ( (in_array(osc_category_id(), osc_search_category()) || in_array(osc_category_slug()."/", osc_search_category()) || count(osc_search_category())==0 ) ? 'checked' : '') ; ?> /> <label for="cat<?php echo osc_category_id(); ?>"><strong><?php echo osc_category_name(); ?></strong></label>
<?php if(osc_count_subcategories()){ ?>
<?php while(osc_has_subcategories()) { ?>
<?php if(osc_category_slug()==$category || osc_category_id()==$sCategory || osc_category_id()==$sCategory2) { ?>
<br />>><input type="checkbox" id="cat<?php echo osc_category_id(); ?>" name="sCategory[]" value="<?php echo osc_category_id(); ?>" <?php echo 'checked'; ?> /> <label for="cat<?php echo osc_category_id(); ?>"><strong><?php echo osc_category_name(); ?></strong></label>
<?php } ?>
<?php } ?>
<?php } ?>
</li>
<?php } ?>
</ul>
</div>
<?php } ?>
Notes and references
--Jesse 14:16, 21 December 2011 (CET)

