Datafeedr Support Forums

Datafeedr Support Forums (http://www.datafeedr.com/forums/index.php)
-   Tips, Tricks & Tutorials (http://www.datafeedr.com/forums/forumdisplay.php?f=66)
-   -   Drop down menus for Brands, Merchants and Networks (http://www.datafeedr.com/forums/showthread.php?t=6778)

Eric April 18th, 2012 09:11 AM

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

Eric June 11th, 2012 02:03 PM

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

outdoorcampingshops January 14th, 2013 03:35 PM

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!

Eric January 14th, 2013 03:37 PM

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

outdoorcampingshops January 14th, 2013 03:41 PM

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 ;)

Eric January 14th, 2013 03:45 PM

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

outdoorcampingshops January 14th, 2013 04:09 PM

:eek:
Perfect


Cheers! Thanks

emersonscherer March 1st, 2013 04:42 PM

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.

Eric March 1st, 2013 04:49 PM

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

emersonscherer March 1st, 2013 05:06 PM

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

Blauwdruk March 3rd, 2013 10:41 AM

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?

Eric March 3rd, 2013 10:52 AM

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

welike December 1st, 2013 12:24 PM

How do you put the dropdowns next to each other?

Eric December 1st, 2013 01:46 PM

Hi

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

Eric

welike January 8th, 2014 04:40 AM

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

Eric January 8th, 2014 09:56 AM

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

mlt01005 January 23rd, 2014 01:11 PM

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?

Eric January 23rd, 2014 01:21 PM

Hi,

Thanks for your kind words.

Unfortunately it will not work 3 levels deep.

Eric

mlt01005 January 23rd, 2014 01:32 PM

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/

Eric January 23rd, 2014 01:34 PM

Well, looks good to me! :)


All times are GMT -5. The time now is 10:52 PM.

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