![]() |
|
Home | Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
Thread Tools | Search this Thread | Display Modes |
#1
|
|||
|
|||
![]() www.thekitchentool.com
Store Id: 30751 Hi Eric, I have some hard-coded brand filters on each category and I'm trying to generate those dynamically so that I don't have to worry about them getting out of sync with the products. Based on other posts I saw, I gave it an initial try... and clearly my syntax is erroneous somewhere as the Brand Filter no longer shows up. I'm trying it on the Woks category under Cookware. Can you please help? I added the following function to my functions.php: //Function to Get Brands of Woks Category function dfr_get_brands() { global $wpdb; $merchants = $wpdb->get_results("SELECT DISTINCT p.brand FROM ".$wpdb->prefix."dfr_shop_products p, ".$wpdb->prefix."wp_dfr_shop_p2c pc, ".$wpdb->prefix."wp_dfr_shop_cats c AND pc.cat_id = c.id AND c.name = \'Woks\' ORDER BY c.name, p.brand"); $list = array(); foreach ($brands as $brands) { $list[$brands->brand] = $brands->brand; } return $list; } Then to the filter Widget, I added: <div> <form method="get"> <span> <?php echo datafeedr_tools()->form_select("brand", array( "" => "All Brands", ?> <?php $brands = dfr_get_brands(); foreach ($brands as $brandname) { echo '\"'$brandname'\" => \"'$brandname'\",'; } ?> )); <input type="submit" value="Go" /> </span> </form> </div> My goal is to generate the following code, for example: <div> <form method="get"> <span> <?php echo datafeedr_tools()->form_select("brand", array( "" => "All Brands", "All-Clad" => "All-Clad", "Anolon" => "Anolon", "Calphalon" => "Calphalon", "Circulon" => "Circulon", "Cuisinart" => "Cuisinart", "Le Creuset" => "Le Creuset", "West Bend" => "West Bend" )); ?> <input type="submit" value="Go" /> </span> </form> </div> |
#2
|
||||
|
||||
![]() Hi
You can't perform a foreach() loop inside the form_select() function call. You'll just have to create the <select> drop down box using your own HTML code and not the form_select() function. Eric
__________________
![]() ![]() ![]() ![]() |
#3
|
|||
|
|||
![]() Thanks, is there any other way you can think of to enable some sort of dynamic list?
|
#4
|
||||
|
||||
![]() Something like this should work:
HTML Code:
<?php //Function to Get Brands function dfr_get_brands() { global $wpdb; $merchants = $wpdb->get_results("SELECT DISTINCT p.brand FROM ".$wpdb->prefix."dfr_shop_products p, ".$wpdb->prefix."wp_dfr_shop_p2c pc, ".$wpdb->prefix."wp_dfr_shop_cats c AND pc.cat_id = c.id AND c.name = \'Woks\' ORDER BY c.name, p.brand"); $html = ''; foreach ($brands as $brands) { $html .= '<option value="'.$brands->brand.'">'.$brands->brand.'</option>'; } return $html; } ?> <!-- code for your vuew --> <form method="get"> <span> <?php echo dfr_get_brands(); ?> <input type="submit" value="Go" /> </span> </form>
__________________
![]() ![]() ![]() ![]() |
#5
|
|||
|
|||
![]() Thanks Eric, I tried putting all of that code in the view and received the following error:
Warning: Invalid argument supplied for foreach() in /home/content/69/7529569/html/wp-content/plugins/datafeedr/datafeedr.php(1981) : eval()'d code on line 8 I also tried putting the function in functions.php after removing the php beginning and ending markers and then the bottom view code alone in the view but I then received a parse error. Thanks |
#6
|
||||
|
||||
![]() The function is supposed to go in your theme's functions.php file and the html code is supposed to go into your view.
__________________
![]() ![]() ![]() ![]() |
#7
|
|||
|
|||
![]() Yes, I also tried putting the function in functions.php after removing the php beginning and ending markers and then the bottom view code alone in the view but I then received a parse error.
Thanks, Melissa |
#8
|
||||
|
||||
![]() Hi
I think your query is completely wrong. I did this and it worked: Code for theme's functions.php file: PHP Code:
HTML Code:
<form method="get"> <select name="brand"> <?php echo dfr_get_brands(); ?> <input type="submit" value="Go" /> </select> </form>
__________________
![]() ![]() ![]() ![]() |
#9
|
|||
|
|||
![]() I´m a bit confused, where did you put this code?
|
#10
|
||||
|
||||
![]() The function dfr_get_brands() { ... } goes in your theme's functions.php file.
The other HTML code goes in one of your Views.
__________________
![]() ![]() ![]() ![]() |
#11
|
|||
|
|||
![]() Help please - I have just pasted The function dfr_get_brands() { ... } goes in your theme's functions.php file. (I assume you meant the wordpress theme)
and... HTTP Error 500 (Internal Server Error) - really not sure what to do - HELPP |
#12
|
||||
|
||||
![]() Sounds like you either didn't paste the whole thing or you pasted outside of the opening/closing php tags (ie. <?php ... ?>)
__________________
![]() ![]() ![]() ![]() |
#13
|
|||
|
|||
![]() Hi Eric,
The code I pasted in was: function dfr_get_brands() { global $wpdb; $brands = $wpdb->get_results("SELECT brand FROM ".$wpdb->prefix."dfr_shop_products GROUP BY brand"); $html = ''; foreach ($brands as $brands) { $html .= '<option value="'.$brands->brand.'">'.$brands->brand.'</option>'; } return $html; } How do I now get the site back live - as I cant login to my wordpress theme www.designerlabeldeals.co.uk Any help to get it back up and running would be really appreciated Thanks |
#14
|
||||
|
||||
![]() The first step to getting your site back online is to remove all of the code your pasted into your functions.php file and save it again. Then you will be able to log back into your site.
__________________
![]() ![]() ![]() ![]() |
#15
|
|||
|
|||
![]() Hi Eric - fortunately my son has just arrived back and got the site live again - doing exactly what you just suggested.
Many thanks |
#16
|
|||
|
|||
![]() Store ID: 32722
Website URL: http://www.meinehandtasche.de/ URL to page in question: http://www.meinehandtasche.de/store/ Hi Eric, I copied this code into the functions.php of my wordpress theme (lifestyle from studiopress): Quote:
Quote:
http://www.meinehandtasche.de/store and you can see the black list of words under the header "MARKEN". I don't have a clue actually what this list is showing. The result should look like under the header "MARKEN FILTER". Do you have any idea what went wrong? Thanks, Oliver |
#17
|
||||
|
||||
![]() I don't think you copied the code correctly. The code you need in your functions.php file is in post #8.
Also, it looks like the correct code for your view is this: HTML Code:
<form method="get"> <select name="brand"> <?php echo dfr_get_brands(); ?> <input type="submit" value="Go" /> </select> </form>
__________________
![]() ![]() ![]() ![]() |
#18
|
|||
|
|||
![]() Store ID: 32722
Website URL: http://www.meinehandtasche.de/ URL to page in question: http://www.meinehandtasche.de/store/ Thank you Eric! :-) Now the drop down shows all brands. Is there a way to manage which brands should show up in the drop down? Additionally the brands show up in different style (some capital letter some small etc.). Thanks, Oliver |
#19
|
||||
|
||||
![]() Hi
Quote:
Quote:
__________________
![]() ![]() ![]() ![]() |
#20
|
||||
|
||||
![]() Here's an example of how to remove brands from the list. I've removed 'Adidas' and 'Atlas'. This example also shows how to capitalize the first letter in each word of the brand.
PHP Code:
__________________
![]() ![]() ![]() ![]() |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Merchant and Brand filter Widgets | Nugerama | Tips, Tricks & Tutorials | 13 | March 7th, 2012 05:01 PM |
Brand Filter Drop-Down with All Brands option | meperez | Questions | 8 | March 26th, 2011 12:04 AM |
Brand Filter = Brands Only show when in Category | macfink | Questions | 3 | March 25th, 2011 12:55 PM |
Drop down Menu from filter by Brand | macfink | Questions | 4 | March 25th, 2011 09:32 AM |
Brand filter? | sylviathewitch | Problems | 3 | March 8th, 2011 08:43 AM |