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
  #1  
Old April 18th, 2012, 09:11 AM
Eric's Avatar
Eric Eric is offline
Datafeedr Team
 
Join Date: Feb 2008
Posts: 16,902
Default Drop down menus for Brands, Merchants and Networks

Here's how to add a <select> dropdown menu for brands, merchants and networks. 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(); ?>
	</select>
	
	<!-- Merchant drop down select menu -->
	<select name="merchant_id">
		<?php echo dfr_get_merchants(); ?>
	</select>
	
	<!-- Network drop down select menu -->  
	<select name="net_id">
		<?php echo dfr_get_networks(); ?>
	</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() {
    global 
$wpdb;
    
$brands $wpdb->get_results("SELECT brand FROM ".$wpdb->prefix."dfr_shop_products 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() {
    global 
$wpdb;
    
$merchants $wpdb->get_results("SELECT merchant, merchant_id FROM ".$wpdb->prefix."dfr_shop_products 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() {
    global 
$wpdb;
    
$networks $wpdb->get_results("SELECT network, net_id FROM ".$wpdb->prefix."dfr_shop_products 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
  #2  
Old June 11th, 2012, 02:03 PM
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. 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();
	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();
	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();
	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() {
    global 
$wpdb;
    
$brands $wpdb->get_results("SELECT brand FROM ".$wpdb->prefix."dfr_shop_products GROUP BY brand");
    
$list = array();
    foreach (
$brands as $brands) {
        
$brand trim($brands->brand);
        if (
$brand != "") {
            
$list[] = $brand;
        }
    }
    return 
$list;


function 
dfr_get_merchants_list() {
    global 
$wpdb;
    
$merchants $wpdb->get_results("SELECT merchant, merchant_id FROM ".$wpdb->prefix."dfr_shop_products 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() {
    global 
$wpdb;
    
$networks $wpdb->get_results("SELECT network, net_id FROM ".$wpdb->prefix."dfr_shop_products 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
  #3  
Old January 14th, 2013, 03:35 PM
outdoorcampingshops outdoorcampingshops is offline
 
Join Date: Jan 2013
Posts: 42
Default

Great info! I'm a pretty big dubie to this so bare with me...

Do you have a list html code for a widget that will pull categories and subcategories? Thus not having to make about 50 pages manually?

cheers!
  #4  
Old January 14th, 2013, 03:37 PM
Eric's Avatar
Eric Eric is offline
Datafeedr Team
 
Join Date: Feb 2008
Posts: 16,902
Default

Hi,

Welcome to the forums!

That comes with Datafeedr by default. It can be found in your Widgets > Datafeedr > Categories.

See this video: http://www.datafeedr.com/videos?vide...rc=yt#videotop

Eric
  #5  
Old January 14th, 2013, 03:41 PM
outdoorcampingshops outdoorcampingshops is offline
 
Join Date: Jan 2013
Posts: 42
Default

Eric, Thanks.

I know it shows the main categories but am hoping it would also show all subcategories from the get-go. One click vs two clicks
  #6  
Old January 14th, 2013, 03:45 PM
Eric's Avatar
Eric Eric is offline
Datafeedr Team
 
Join Date: Feb 2008
Posts: 16,902
Default

Hi,

Sure, that's possible.

1. Go here: The Factory > Your Store > VIEWS > WIDGET > Categories > category list module

2. Click the edit theme image ( () )

3. Replace ALL of the code in there with the following code (found in the snippets in the left sidebar):

HTML Code:
[category.list before='<ul>' after='</ul>']
<li>
  <a href="[category.link]" title="[category.name]">[category.name]</a>
  [category.repeat]
</li>
[/category.list]
4. Save and click the [Update Settings Only] on your site.

Eric
  #7  
Old January 14th, 2013, 04:09 PM
outdoorcampingshops outdoorcampingshops is offline
 
Join Date: Jan 2013
Posts: 42
Default


Perfect


Cheers! Thanks
  #8  
Old March 1st, 2013, 04:42 PM
emersonscherer emersonscherer is offline
 
Join Date: Apr 2012
Posts: 12
Default Results based on categories

Hello,

Is this a contextual display or brands or just brands in general? I came across another users post where they asked you how to show brands related to a category and copied there code which worked great, however, for some reason it will not work on a top level category.

Do you have a functional piece of code laying around to put a contextual list of brands in a widget, if so, that would be greatly appreciated.
  #9  
Old March 1st, 2013, 04:49 PM
Eric's Avatar
Eric Eric is offline
Datafeedr Team
 
Join Date: Feb 2008
Posts: 16,902
Default

Hi,

I'm guessing you're referring to this code: http://www.datafeedr.com/forums/show...5993#post35993

There is a limitation to that code and that is if you have categories nested more than 2 levels deep, it will not work at the top level. It will require too much MySQL resources to create that query.

Eric
  #10  
Old March 1st, 2013, 05:06 PM
emersonscherer emersonscherer is offline
 
Join Date: Apr 2012
Posts: 12
Default

Actually, no, I was referring to a different post, however, the one your referenced was exactly the code I was looking for. Problem solved. Ty
  #11  
Old March 3rd, 2013, 10:41 AM
Blauwdruk Blauwdruk is offline
 
Join Date: Feb 2013
Posts: 1
Default

Hi Eric,

Thanks for this, it's really useful!

Is it also possible to add the price filter and color filter to the dropdown form?
  #12  
Old March 3rd, 2013, 10:52 AM
Eric's Avatar
Eric Eric is offline
Datafeedr Team
 
Join Date: Feb 2008
Posts: 16,902
Default

Hi,

Welcome to the forums!

The price and color filters would have to be created manually as the queries for those to facets are difficult/impossible to create.

Here's an example of Price and Color filters which could be modified to be used as a drop down: http://www.datafeedr.com/forums/showthread.php?t=3853

Eric
  #13  
Old December 1st, 2013, 12:24 PM
welike welike is offline
 
Join Date: Nov 2013
Posts: 12
Default

How do you put the dropdowns next to each other?
  #14  
Old December 1st, 2013, 01:46 PM
Eric's Avatar
Eric Eric is offline
Datafeedr Team
 
Join Date: Feb 2008
Posts: 16,902
Default

Hi

By default they should. However you need to have a lot of room to do that.

Eric
  #15  
Old January 8th, 2014, 04:40 AM
welike welike is offline
 
Join Date: Nov 2013
Posts: 12
Default

Hi,

How can I add the drop downs next to the pagination in Category page view / Product list template?

Store ID: 43499
Website URL: welikesale.nl
URL to page in question: http://welikesale.nl/c/damesschoenen...llaarsjes-sale
  #16  
Old January 8th, 2014, 09:56 AM
Eric's Avatar
Eric Eric is offline
Datafeedr Team
 
Join Date: Feb 2008
Posts: 16,902
Default

Hi,

You will need to add the code from above into the section of your Product list module that has the CSS class of pgr. However there's not much room in that section and styling will be tricky.

Eric
  #17  
Old January 23rd, 2014, 01:11 PM
mlt01005 mlt01005 is offline
 
Join Date: Oct 2012
Posts: 9
Default

First I just want to say that I'm impressed with the timely manner of support by datafeedr staff to resolve issues and respond to customer needs, it's one of the best I've seen by a wordpress plugin owner, A+++.

Second, I just want to say when I used the function calls for a brand/merchant filter function above it included all brands and merchants and were not category specific. Instead I used the functions in this thread: http://www.datafeedr.com/forums/show...5993#post35993

I do however want to confirm the note above. If I have a main category, then two levels of sub-categories below it, will the aforementioned functions work on all three levels?
  #18  
Old January 23rd, 2014, 01:21 PM
Eric's Avatar
Eric Eric is offline
Datafeedr Team
 
Join Date: Feb 2008
Posts: 16,902
Default

Hi,

Thanks for your kind words.

Unfortunately it will not work 3 levels deep.

Eric
  #19  
Old January 23rd, 2014, 01:32 PM
mlt01005 mlt01005 is offline
 
Join Date: Oct 2012
Posts: 9
Default

Ok thanks however it seems to be working properly, can I get a second look? Here is an example category three levels deep: http://www.petiteoutdoor.com/store/c...dration-packs/
  #20  
Old January 23rd, 2014, 01:34 PM
Eric's Avatar
Eric Eric is offline
Datafeedr Team
 
Join Date: Feb 2008
Posts: 16,902
Default

Well, looks good to me!
 


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 12:27 AM.


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