Datafeedr Support Forums

Datafeedr Support Forums (/index.php)
-   Questions (/forumdisplay.php?f=67)
-   -   Create a Dropdown Menu for Custom Filters (/showthread.php?t=9082)

urbaniteuk May 9th, 2013 12:05 PM

Create a Dropdown Menu for Custom Filters
 
1 Attachment(s)
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

Eric May 9th, 2013 12:12 PM

Here you go: /showthread.php?t=6778

urbaniteuk May 9th, 2013 12:49 PM

Cheers Eric!

urbaniteuk May 10th, 2013 04:34 AM

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.

Eric May 10th, 2013 08:56 AM

Hi
Quote:

Originally Posted by urbaniteuk (Post 42092)
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 (Post 42092)
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 (Post 42092)
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

urbaniteuk May 10th, 2013 09:11 AM

1. I was referring to this code:

Quote:

Originally Posted by Eric (Post 35993)
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.

urbaniteuk May 10th, 2013 09:34 AM

Eric,

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

http://theurbanite.co.uk/marketplace/category/mens/

Eric May 10th, 2013 09:49 AM

Quote:

Originally Posted by urbaniteuk (Post 42099)
1. I was referring to this code:

Thanks for clarifying the other points.

You can just Add that code.


Quote:

Originally Posted by urbaniteuk (Post 42100)
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>


urbaniteuk May 10th, 2013 11:07 AM

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

urbaniteuk May 10th, 2013 11:08 AM

Sorry, the code doesn't filter the related Merchants to a category either.

Eric May 10th, 2013 12:19 PM

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

urbaniteuk May 10th, 2013 12:58 PM

Eric, that's brilliant!!!

Thank you so much… Have a great weekend!

Eric May 10th, 2013 12:59 PM

Quote:

Originally Posted by urbaniteuk (Post 42116)
Eric, that's brilliant!!!

Thank you so much Have a great weekend!

Glad it worked for you! :)

urbaniteuk May 16th, 2013 01:59 AM

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?

Eric May 16th, 2013 06:21 AM

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

urbaniteuk May 16th, 2013 07:52 AM

Thanks Eric,

That's Great! :)

urbaniteuk May 16th, 2013 08:38 AM

One last thing… Not! :)

Is a category drop down created the same way or will this require a different code?

urbaniteuk May 16th, 2013 10:10 AM

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.

Eric May 16th, 2013 10:24 AM

Hi,

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

Eric

urbaniteuk May 16th, 2013 01:38 PM

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… :/


All times are GMT -5. The time now is 12:56 PM.

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