View Single Post
  #22  
Old October 21st, 2014, 09:26 AM
Eric's Avatar
Eric Eric is offline
Datafeedr Team
 
Join Date: Feb 2008
Posts: 16,902
Default

Here's how to add a <ul> HTML list menu for brands, merchants and networks which gets filtered by category This filters to 1 category level deep so it's not a perfect solution for filtering per category. If you are not comfortable editing PHP or HTML code, this tutorial might not be for you.

You don't have to use them all but you can if you want. Here's what it will look like:



1. Go here: The Factory > Your Store > VIEWS > WIDGETS > Add a new view

2. Name the view "Drop Down Filters"

3. Add a Text module to the view

4. Add the following code to the Text module:

HTML Code:
<h4>Brand Filter</h4>
<ul>
	<?php 
	$brands = dfr_get_brands_list($category->id);
	foreach ($brands as $brand) : ?>
		<li><a href="[server.url type='fullpage' query='brand=$brand']"><?php echo $brand; ?></a></li>
	<?php endforeach; ?>
</ul>

<h4>Merchant Filter</h4>
<ul>
	<?php 
	$merchants = dfr_get_merchants_list($category->id);
	foreach ($merchants as $merchant_id => $merchant) : ?>
		<li><a href="[server.url type='fullpage' query='merchant_id=$merchant_id']"><?php echo $merchant; ?></a></li>
	<?php endforeach; ?>
</ul>

<h4>Network Filter</h4>
<ul>
	<?php 
	$networks = dfr_get_networks_list($category->id);
	foreach ($networks as $net_id => $network) : ?>
		<li><a href="[server.url type='fullpage' query='net_id=$net_id']"><?php echo $network; ?></a></li>
	<?php endforeach; ?>
</ul>
5. Save the view.

6. Open your theme's functions.php file (usually found here: /wp-content/themes/YOUR-THEME/functions.php)

7. Add the following PHP code to the bottom of the file:

PHP Code:
function dfr_get_brands_list$cat=false ) {
    global 
$wpdb;
       
$cat_query = ($cat) ? "WHERE p2c.cat_id = ".intval($cat)." " "";
    
$brands $wpdb->get_results("     
        SELECT brand, p2c.cat_id 
        FROM "
.$wpdb->prefix."dfr_shop_products AS p 
        INNER JOIN "
.$wpdb->prefix."dfr_shop_p2c AS p2c ON p.id = p2c.id 
        
$cat_query 
        GROUP BY brand 
    "
); 
    
$list = array();
    foreach (
$brands as $brands) {
        
$brand trim($brands->brand);
        if (
$brand != "") {
            
$list[] = $brand;
        }
    }
    return 
$list;


function 
dfr_get_merchants_list$cat=false ) {
    global 
$wpdb;
       
$cat_query = ($cat) ? "WHERE p2c.cat_id = ".intval($cat)." " "";
    
$merchants $wpdb->get_results("
        SELECT merchant, merchant_id, p2c.cat_id 
        FROM "
.$wpdb->prefix."dfr_shop_products AS p 
        INNER JOIN "
.$wpdb->prefix."dfr_shop_p2c AS p2c ON p.id = p2c.id 
        
$cat_query 
        GROUP BY merchant
    "
);
    
$list = array();
    foreach (
$merchants as $k => $v) {
        
$merchant trim($v->merchant);
        if (
$merchant != "") {
            
$list[$v->merchant_id] = $merchant;
        }
    }
    return 
$list;


function 
dfr_get_networks_list$cat=false ) {
    global 
$wpdb;
       
$cat_query = ($cat) ? "WHERE p2c.cat_id = ".intval($cat)." " "";
    
$networks $wpdb->get_results("
        SELECT network, net_id, p2c.cat_id 
        FROM "
.$wpdb->prefix."dfr_shop_products AS p 
        INNER JOIN "
.$wpdb->prefix."dfr_shop_p2c AS p2c ON p.id = p2c.id 
        
$cat_query 
        GROUP BY net_id
    "
);
    
$list = array();
    foreach (
$networks as $k => $v) {
        
$network trim($v->network);
        if (
$network != "") {
            
$list[$v->net_id] = $network;
        }
    }
    return 
$list;

8. Save the functions.php file.

9. Add the new "Drop Down Filters" widget to your sidebar here: WordPress Admin Area > Appearance > Widgets

That's it.

Eric