Datafeedr Support Forums  

Go Back   Datafeedr Support Forums > Current Version (V3) Forum > Questions
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 May 9th, 2013, 12:05 PM
urbaniteuk urbaniteuk is offline
 
Join Date: Apr 2013
Posts: 120
Default Create a Dropdown Menu for Custom Filters

Store ID: The Urbanite Store
Website URL: http;//theurbanite.co.uk
URL to page in question: http://theurbanite.co.uk/marketplace/category/mens

Hi Guys,

I cannot find the answer on the forum, so I have to ask for guidance

How can I create a Drop-down menu for my custom filters, as my brand list goes on forever?

Many thanks
Attached Thumbnails
Click image for larger version

Name:	Screen Shot 2013-05-09 at 17.57.43.png
Views:	195
Size:	47.6 KB
ID:	561  
  #2  
Old May 9th, 2013, 12:12 PM
Eric's Avatar
Eric Eric is offline
Datafeedr Team
 
Join Date: Feb 2008
Posts: 16,902
Default

Here you go: /showthread.php?t=6778
  #3  
Old May 9th, 2013, 12:49 PM
urbaniteuk urbaniteuk is offline
 
Join Date: Apr 2013
Posts: 120
Default

Cheers Eric!
  #4  
Old May 10th, 2013, 04:34 AM
urbaniteuk urbaniteuk is offline
 
Join Date: Apr 2013
Posts: 120
Default

Hi Eric,

Hope all is well?

Further to my query. Please could you advise on the following:

I have placed the code as advised, but in addition I would like the drop down filters to list category related Brands and Merchants (ie. Mens > Mens Brands > Related Merchants).

1. I believe this is what I need, but I'm not 100% sure where to incorporate the codes… Do I need to REPLACE or ADD this code to my existing functions.php file?

/show...5993#post35993

My current functions.php file looks like this:

Quote:
<?php
################################# FIX IE 7 bugs #############################################
add_action( 'wp_head', 'ie_conditional' );
if (!function_exists('ie_conditional')) {
function ie_conditional()
{
echo "
<!--[if IE 7]>
<style>
#sidebar { margin-top:-16px;}
body.home #sidebar { margin-top:0px;}
#plusone-div {padding: 0 0 10px !important;}
#plusone-div {position:absolute;margin:12px 0 0 0 !important;display:inline;padding: 0 0 10px !important;}
</style>
<![endif]-->
<!--[if IE 8]>
<style>
#plusone-div {position:absolute;margin:12px 0 0 0 !important;display:inline;padding: 0 0 10px !important;}
</style>
<![endif]-->
";
}}

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;
}
################################# END FIX FOR FACEBOOK LIKE THUMB URL ##########################################
?>

2. Where in the factory do I add this code?

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

3. Is there a way to re-size the width of the drop downs, as I would like to keep the sizes consistent (Select a Brand/Select a Merchant)?

Many thanks.
  #5  
Old May 10th, 2013, 08:56 AM
Eric's Avatar
Eric Eric is offline
Datafeedr Team
 
Join Date: Feb 2008
Posts: 16,902
Default

Hi
Quote:
Originally Posted by urbaniteuk View Post
1. I believe this is what I need, but I'm not 100% sure where to incorporate the codes Do I need to REPLACE or ADD this code to my existing functions.php file?

/show...5993#post35993
The link you posted is broken so I'm not sure what code you are referring to.

Quote:
Originally Posted by urbaniteuk View Post
2. Where in the factory do I add this code?
You create a Widget view, add a Text module to the Widget and paste that code into the Text module.

Quote:
Originally Posted by urbaniteuk View Post
3. Is there a way to re-size the width of the drop downs, as I would like to keep the sizes consistent (Select a Brand/Select a Merchant)?
Try adding this to your Custom CSS:
Code:
#sidebar select {
width: 200px;
}
Eric
  #6  
Old May 10th, 2013, 09:11 AM
urbaniteuk urbaniteuk is offline
 
Join Date: Apr 2013
Posts: 120
Default

1. I was referring to this code:

Quote:
Originally Posted by Eric View Post
Hi

Try using this instead in your functions.php file:
PHP Code:
function dfr_get_brands_list($category) {
    global 
$wpdb;
    
$cat_query "";
    if (
$category) { 
        
$in = array();
        
$in[] = $category->id;
        if (!empty(
$category->children)) {
            foreach (
$category->children as $child => $id) {
                
$in[] = $id;
            }
        }
        
$category_ids implode(","$in);
        
$cat_query "WHERE p2c.cat_id IN (".$category_ids.") "
    }
    
$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;

And this in your view in the Factory:
HTML Code:
<ul>
<?php 
$brands = dfr_get_brands_list($category);
foreach ($brands as $brand) : ?>
  <li><a href="[server.url type='fullpage' query='brand=$brand']"><?php echo $brand; ?></a></li>
<?php endforeach; ?>
</ul>
Eric
Thanks for clarifying the other points.
  #7  
Old May 10th, 2013, 09:34 AM
urbaniteuk urbaniteuk is offline
 
Join Date: Apr 2013
Posts: 120
Default

Eric,

Do you have a code to change the Price Filter into a Drop down menu?

http://theurbanite.co.uk/marketplace/category/mens/
  #8  
Old May 10th, 2013, 09:49 AM
Eric's Avatar
Eric Eric is offline
Datafeedr Team
 
Join Date: Feb 2008
Posts: 16,902
Default

Quote:
Originally Posted by urbaniteuk View Post
1. I was referring to this code:

Thanks for clarifying the other points.
You can just Add that code.


Quote:
Originally Posted by urbaniteuk View Post
Eric,

Do you have a code to change the Price Filter into a Drop down menu?

http://theurbanite.co.uk/marketplace/category/mens/
Here's an example:
HTML Code:
<select name="price">
	<option value="-100">Less than $100</option>
	<option value="100-500">Between $100 and $500</option>
	<option value="500-">Over $500</option>
</select>
  #9  
Old May 10th, 2013, 11:07 AM
urbaniteuk urbaniteuk is offline
 
Join Date: Apr 2013
Posts: 120
Default

Quote:
<select name="price">
<option value="-100">Less than $100</option>
<option value="100-500">Between $100 and $500</option>
<option value="500-">Over $500</option>
</select>
I input the code above, which created the drop down. However, the search function didn't work, so I then tried this!

Quote:
<ul>
<?php if (@$_GET['price']) { ?>

<li><a href="[server.url type='fullpage' query='price']">[x] Remove price filter</a></li>'

<?php } else { ?>

<select name="price">
<option value="-50">Less than 50</option>
<option value="50-100">50 ~ 100</option>
<option value="100-250">100 ~ 250</option>
<option value="250-500">250 ~ 500</option>
<option value="500-1000">500 ~ 1,000</option>
<option value="1000-">More than 1,000</option>

</select>

<?php } ?>

</ul>
Obviously, I've lost the plot! lol What have I done wrong?


Also,

I implement this as advised:

Quote:
function dfr_get_brands_list($category) {
global $wpdb;
$cat_query = "";
if ($category) {
$in = array();
$in[] = $category->id;
if (!empty($category->children)) {
foreach ($category->children as $child => $id) {
$in[] = $id;
}
}
$category_ids = implode(",", $in);
$cat_query = "WHERE p2c.cat_id IN (".$category_ids.") ";
}
$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;
}
And this in your view in the Factory:
HTML Code:

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

Eric
It now filters the related brands to a category, but it now displays as a list — not a drop down menu.

Please advise
  #10  
Old May 10th, 2013, 11:08 AM
urbaniteuk urbaniteuk is offline
 
Join Date: Apr 2013
Posts: 120
Default

Sorry, the code doesn't filter the related Merchants to a category either.
  #11  
Old May 10th, 2013, 12:19 PM
Eric's Avatar
Eric Eric is offline
Datafeedr Team
 
Join Date: Feb 2008
Posts: 16,902
Default

Hi,

Here's some updated code.

Add the following code to your theme's functions.php file:

PHP Code:
function dfr_get_brands($category=false) {
    global 
$wpdb;
    
$cat_query "";
    if (@
$category->id) { 
        
$in = array();
        
$in[] = $category->id;
        if (!empty(
$category->children)) {
            foreach (
$category->children as $child => $id) {
                
$in[] = $id;
            }
        }
        
$category_ids implode(","$in);
        
$cat_query "WHERE p2c.cat_id IN (".$category_ids.") "
    }
    
$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 $row) {
        
$brand trim($row->brand);
        if (
$brand != "") {
            
$selected = (strip_tags($_GET['brand'])==$brand) ? ' selected="selected"' '';
            
$html .= '<option value="'.$brand.'"'.$selected.'>'.$brand.'</option>';
        }
    }
    return 
$html;
}  

function 
dfr_get_merchants($category=false) {
    global 
$wpdb;
    
$cat_query "";
    if (@
$category->id) { 
        
$in = array();
        
$in[] = $category->id;
        if (!empty(
$category->children)) {
            foreach (
$category->children as $child => $id) {
                
$in[] = $id;
            }
        }
        
$category_ids implode(","$in);
        
$cat_query "WHERE p2c.cat_id IN (".$category_ids.") "
    }
    
$merchants $wpdb->get_results("
        SELECT merchant, 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 $row) {
        
$merchant trim($row->merchant);
        if (
$merchant != "") {
            
$selected = (strip_tags($_GET['merchant'])==$merchant) ? ' selected="selected"' '';
            
$html .= '<option value="'.$merchant.'"'.$selected.'>'.$merchant.'</option>';
        }
    }
    return 
$html;
}  


function 
dfr_get_networks($category=false) {
    global 
$wpdb;
    
$cat_query "";
    if (@
$category->id) { 
        
$in = array();
        
$in[] = $category->id;
        if (!empty(
$category->children)) {
            foreach (
$category->children as $child => $id) {
                
$in[] = $id;
            }
        }
        
$category_ids implode(","$in);
        
$cat_query "WHERE p2c.cat_id IN (".$category_ids.") "
    }
    
$networks $wpdb->get_results("
        SELECT network, 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 network
    "
);
    
$html '<option value="">Select a network</option>';
       foreach (
$networks as $row) {
        
$network trim($row->network);
        if (
$network != "") {
            
$selected = (strip_tags($_GET['network'])==$network) ? ' selected="selected"' '';
            
$html .= '<option value="'.$network.'"'.$selected.'>'.$network.'</option>';
        }
    }
    return 
$html;

Add the following code to a Text module (in a Widget view):

HTML Code:
<form method="get">
  
  <!-- Brand drop down select menu -->
  <select name="brand">
    <?php echo dfr_get_brands($category); ?>
  </select>
  
  <!-- Merchant drop down select menu -->
  <select name="merchant">
    <?php echo dfr_get_merchants($category); ?>
  </select>
  
  <!-- Network drop down select menu -->  
  <select name="network">
    <?php echo dfr_get_networks($category); ?>
  </select>
  
  <!-- Price filter -->
  <select name="price">
    <option value="-100"<?php if ($_GET['price'] == '-100') { echo ' selected="selected"'; } ?>>Less than $100</option>
    <option value="100-500"<?php if ($_GET['price'] == '100-500') { echo ' selected="selected"'; } ?>>Between $100 and $500</option>
    <option value="500-"<?php if ($_GET['price'] == '500-') { echo ' selected="selected"'; } ?>>Over $500</option>
  </select>
  
  <input type="submit" value="Go" />
  
</form>
That should do the trick.

Eric
  #12  
Old May 10th, 2013, 12:58 PM
urbaniteuk urbaniteuk is offline
 
Join Date: Apr 2013
Posts: 120
Default

Eric, that's brilliant!!!

Thank you so much… Have a great weekend!
  #13  
Old May 10th, 2013, 12:59 PM
Eric's Avatar
Eric Eric is offline
Datafeedr Team
 
Join Date: Feb 2008
Posts: 16,902
Default

Quote:
Originally Posted by urbaniteuk View Post
Eric, that's brilliant!!!

Thank you so much Have a great weekend!
Glad it worked for you!
  #14  
Old May 16th, 2013, 01:59 AM
urbaniteuk urbaniteuk is offline
 
Join Date: Apr 2013
Posts: 120
Default

Hi Stefan,

Hope all is well?

Do you have a code to create a Drop down menu that filters by Sex? ie men, women, girls, boys etc.
or a drop down filters by a custom description?

Last edited by urbaniteuk : May 16th, 2013 at 02:03 AM.
  #15  
Old May 16th, 2013, 06:21 AM
Eric's Avatar
Eric Eric is offline
Datafeedr Team
 
Join Date: Feb 2008
Posts: 16,902
Default

Hi,

You could try adding this code to your <form> from above.

HTML Code:
  <!-- Gender filter -->
  <select name="word">
    <option value="men"<?php if ($_GET['word'] == 'men') { echo ' selected="selected"'; } ?>>Men</option>    
    <option value="women"<?php if ($_GET['word'] == 'women') { echo ' selected="selected"'; } ?>>Women</option> 
    <option value="girls"<?php if ($_GET['word'] == 'girls') { echo ' selected="selected"'; } ?>>Girls</option> 
    <option value="boys"<?php if ($_GET['word'] == 'boys') { echo ' selected="selected"'; } ?>>Boys</option>
  </select>
There is no filter for custom descriptions.

Eric
  #16  
Old May 16th, 2013, 07:52 AM
urbaniteuk urbaniteuk is offline
 
Join Date: Apr 2013
Posts: 120
Default

Thanks Eric,

That's Great!
  #17  
Old May 16th, 2013, 08:38 AM
urbaniteuk urbaniteuk is offline
 
Join Date: Apr 2013
Posts: 120
Default

One last thing… Not!

Is a category drop down created the same way or will this require a different code?
  #18  
Old May 16th, 2013, 10:10 AM
urbaniteuk urbaniteuk is offline
 
Join Date: Apr 2013
Posts: 120
Default

Hi Eric,

Thank you for your help so far!

Basically, I am trying to clean up my store pages for easier navigation, as a result I have been messing around with the menu system.

I now know that I want to achieve the following example structure:


Category (Static List)

Fashion & Lifestyle
- Womens Fashion & Lifestyle

(SEO Friendly)


Advanced Filters (Drop Down Menu)

Select a Product
- Clothing
--- Shirt
--- Top

- Lingerie
--- Bras
--- Knickers

- Accessories
--- Shoes & Boots
--- Bags & Purse


Select a Brand (category related)
- Paul Smith

Select a Merchant (category related)
- House of Fraser

Select a Price
- Less than 100
- 100 - 250

Search

I know we have achieved some of this, but I what to bring it all together!

Sorry to mess you around.

Last edited by urbaniteuk : May 16th, 2013 at 10:19 AM.
  #19  
Old May 16th, 2013, 10:24 AM
Eric's Avatar
Eric Eric is offline
Datafeedr Team
 
Join Date: Feb 2008
Posts: 16,902
Default

Hi,

In this post I've outlined how to make a category drop down menu:
/showthread.php?t=7879

Eric
  #20  
Old May 16th, 2013, 01:38 PM
urbaniteuk urbaniteuk is offline
 
Join Date: Apr 2013
Posts: 120
Default

Hi Eric,

Quote:
In this post I've outlined how to make a category drop down menu:
/showthread.php?t=7879

Unfortunately, this is not really what I'm looking for… I may have confused you with an earlier thread.

What I want to do is this:

1. Create a 2 tier Menu in Factory > Store > Categories

Quote:
Fashion & Lifestyle
- Womens Fashion & Lifestyle
This is done.


2. Create an Advanced Drop Down Filter:

Quote:
Select a 'Product' (default button)
- Clothing
--- Shirt
--- Top
- Lingerie
--- Bras
--- Knickers
- Accessories
--- Shoes & Boots
--- Bags & Purse
The above should allow me to create specific top and subcategories, as this list will change in relation to Point (1). Consider this as tiers 3 and 4

3. Is completed.

Quote:
Select a Brand (default button)
- Paul Smith (Brand relates to featured category)

Select a Merchant (default button)
- House of Fraser (Merchant relates to featured category)

Select a Price
- Less than 100
- 100 - 250

Search Button

However, I would like to combine Points 2 and 3 into one Widget View.

Hope this clarifies… :/

Last edited by urbaniteuk : May 16th, 2013 at 01:49 PM.
 


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
Category specific Dropdown filters camseo Tips, Tricks & Tutorials 32 September 25th, 2012 09:21 AM
Custom Filters ccgmark Tips, Tricks & Tutorials 6 August 9th, 2012 12:46 AM
Category Menu dropdown works but cannot add non Datafeedr menus gutfeelboy Questions 2 August 15th, 2011 08:49 AM
Dropdown Filters Code feri Questions 4 March 6th, 2011 05:32 PM
Custom filters ccgmark Questions 1 February 25th, 2011 04:10 PM


All times are GMT -5. The time now is 01:17 PM.


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