You are here:  » Sidebar filter widget category width fixed?


Sidebar filter widget category width fixed?

Submitted by jbdob on Fri, 2012-10-05 12:03 in

Hello David,

Mine sidebar filter widget shows the category which depends on the width of the category decription. So if the category path is too long, the category also shows the complete width and thus going pass the borders of mine sidebar.

Is there a way to control the width of the different options of the filter widget to a fixed position? I tried this with sidebar settings on mine wordpress theme, but it all moves left/right without putting the filter widget to a fixed position.

Hope you can help and thanks!

Submitted by support on Fri, 2012-10-05 12:25

Hi!

The plugin has a built-in "tidy" sub-string function; so one option would be to display just as many words as fit in, say, 20 characters...

To do this, in pto_search.php look for the following code at line 880 which generates each category option in the drop-down:

$html_categories .= "<option ".($pto_categoryFilter==$product->category?"selected='selected'":"")." value='".htmlentities($product->category,ENT_QUOTES,get_settings("blog_charset"))."'>".$product->category."</option>";

...and REPLACE with:

$html_categories .= "<option ".($pto_categoryFilter==$product->category?"selected='selected'":"")." value='".htmlentities($product->category,ENT_QUOTES,get_settings("blog_charset"))."'>".pto_common_substr($product->category,20)."</option>";

(simply change 20 in the call to pto_common_substr for more or less characters)

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by jbdob on Sat, 2012-10-06 07:34

Hello David,

Thanks!

i can get i to work partly.

When adding the line to the Brand part it does indeed shorten the view-area, not completlely 100%, but is does has effect.

but when i apply it to the Categories, it does nothing.

Can you help further or any other options?

Thanks

Submitted by support on Sun, 2012-10-07 09:20

Hi,

The pto_common_substr() function breaks on the next space following the length parameter (20 in this case) so it's entirely possible that there is a category value that is a fair bit longer than this and maybe not contain spaces at all. One thing to do, which will still ensure that most categories are displayed cleanly, would be to make the pto_common_substr() conversion; and then test the strlen() of the response, and if it is greater than what you want as an absolute maximum (say 30 characters), then truncate to that length.

Have a go as the following as an alternative to the replacement described above:

$displayCategory = pto_common_substr($product->category,20);
if (strlen($displayCategory) > 30) $displayCategory = substr($displayCategory,0,30);
$html_categories .= "<option ".($pto_categoryFilter==$product->category?"selected='selected'":"")." value='".htmlentities($product->category,ENT_QUOTES,get_settings("blog_charset"))."'>".$displayCategory."</option>";

Hope this helps!

Cheers,
David.
--
PriceTapestry.com