Datafeedr Support Forums  

Go Back   Datafeedr Support Forums > Current Version (V3) Forum > Tips, Tricks & Tutorials
Home Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Important - The support forums are now in "read-only" mode as we transition to an alternative help desk solution. Feel free to contact us here with any of your questions or search the forums for an existing solution.
 
 
Thread Tools Search this Thread Display Modes
  #21  
Old October 21st, 2014, 09:25 AM
Eric's Avatar
Eric Eric is offline
Datafeedr Team
 
Join Date: Feb 2008
Posts: 16,902
Default

Here's how to add a <select> dropdown 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:
<form method="get">
  
	<!-- Brand drop down select menu -->
	<select name="brand">
		<?php echo dfr_get_brands($category->id); ?>
	</select>
	
	<!-- Merchant drop down select menu -->
	<select name="merchant_id">
		<?php echo dfr_get_merchants($category->id); ?>
	</select>
	
	<!-- Network drop down select menu -->  
	<select name="net_id">
		<?php echo dfr_get_networks($category->id); ?>
	</select>
	
	<input type="submit" value="Go" />
  
</form>
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$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 
    "
); 
    
$html '<option value="">Select a brand</option>'
    foreach (
$brands as $brands) { 
        if (
trim($brands->brand) != "") { 
            
$selected = (strip_tags(stripslashes($_GET['brand']))==$brands->brand) ? ' selected="selected"' ''
            
$html .= '<option value="'.$brands->brand.'"'.$selected.'>'.$brands->brand.'</option>'
        } 
    } 
    return 
$html
}

function 
dfr_get_merchants$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
    "
);
    
$html '<option value="">Select a merchant</option>';
    foreach (
$merchants as $k => $v) {
        if (
trim($v->merchant) != "") {
            
$selected = (strip_tags($_GET['merchant_id'])==$v->merchant_id) ? ' selected="selected"' '';
            
$html .= '<option value="'.$v->merchant_id.'"'.$selected.'>'.$v->merchant.'</option>';
        }
    }
    return 
$html;


function 
dfr_get_networks$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
    "
);
    
$html '<option value="">Select a network</option>';
    foreach (
$networks as $k => $v) {
        if (
$v->net_id 0) {
            
$selected = (strip_tags($_GET['net_id'])==$v->net_id) ? ' selected="selected"' '';
            
$html .= '<option value="'.$v->net_id.'"'.$selected.'>'.$v->network.'</option>';
        }
    }
    return 
$html;

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
  #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
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Brand Filter Drop-Down with All Brands option meperez Questions 8 March 26th, 2011 12:04 AM
Add drop down menus for store categories ccgmark Tips, Tricks & Tutorials 13 January 28th, 2011 01:34 PM
Adding 'products per page' and 'sort by' drop down menus to pages lbuilta59 Questions 1 January 27th, 2011 10:36 AM


All times are GMT -5. The time now is 09:42 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.