Jump to content

Adding active class to link by regex match


laanes

Recommended Posts

Hi,

 

I am adding "active_filter", "passive_filter" classes to links based on regex pattern coming from the URL:

Line 46: https://github.com/laanes/product_filtering/blob/master/APF_URL.php

 

The function gets called on line 89 in here: https://github.com/laanes/product_filtering/blob/master/boxes/advanced_product_filtering_box.inc.php

 

You can see it in action here: http://www.swanseatimber.co.uk/shop/hafele/brand_281.html by clicking on a category on the left, under the heading "Filter Your Results".

 

The clicked category gets a green background because of the added "active_filter" class. When you click again, it will get "passive_filter" class and the products are not filtered any more.

 

The problem: When moving to other pages by using the pagination at the top of the product results, the class doesn't get added.

 

Therefore, you can't remove the filter because function creating the href on line 72 in here: https://github.com/laanes/product_filtering/blob/master/APF_URL.php

 

and the function clearing all filters on line 100 in here: https://github.com/laanes/product_filtering/blob/master/APF_URL.php both fail.

 

What's interesting - when selecting a filter, moving to the next page, clicking in the browser url bar and hiting enter(hard reload i think?), the problem disappears and you can play with the filters again.

 

I really hope you find a minute to look into it and help me.

 

Link to comment
Share on other sites

To build pagination links, without altering any other existing get parameters, see the code in this post - http://www.phpfreaks.com/forums/index.php?topic=348834.msg1646676#msg1646676

 

If you need to completely remove any specific key/value (i.e. filter) from a URL, simply unset the corresponding $_GET value before using http_build_query to build any link. See this post for an example - http://www.phpfreaks.com/forums/index.php?topic=346257.msg1634757#msg1634757

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.