borisdollar Posted September 27, 2012 Share Posted September 27, 2012 Hi, i'm new here and probably a bit out of my depth with PHP. I'll try to explain my problem as best as I possibly can. I have a Wordpress theme which has a section for creating a portfolio. I have populated the portfolio with various images, and the images are split into categories. For arguments sake, lets call them Category1, Category2, Category3 (all the way up to Category7). The portfolio also has a filter which allows the user to select "Category2" and then only images in Category2 will be shown. Nothing too clever there. However, I had to split the portfolio into 2 separate portfolios, quite simply because I have too many categories to filter. So to cut a long story short, I have 2 portfolios. Portfolio1 contains categories1/2/3/4/5 and Portfolio2 contains categories6/7. This works fine, except for the filter. Lets take Portfolio2 for example. It correctly only shows images in Category6 and Category7. But the filter at top has all the categories listed there, when really I only want the filter to show Category6 and Category7. I've pinpointed the code in portfolio.php that controls these filters and this is what it is: <h2><a class="catlink" href="#filter=*" rel="nofollow">Show All</a> <?php $categories = get_terms("portfoliocategory"); foreach ($categories as $category) { $entrycategory = str_replace(',','',str_replace('.','',$category->name)); echo '<a class="catlink" href="#filter=.'.$entrycategory .'" rel="nofollow">'.$category->name.'</a>'; } ?> </h2> So the code above shows filters for all categories. How can I show filters for just the 2 categories? Your help would be much appreciated. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/268855-php-wordpress/ Share on other sites More sharing options...
Psycho Posted September 27, 2012 Share Posted September 27, 2012 I am not familiar with Word Press and so I'm not sure what part of that code is core to WP or what the best ways are to accomplish this in that framework. But, it would seem to me that the best solution would be to modify the get_terms() function to only return the categories you want. That function currently takes one parameter - the string "portfoliocategory". I don't know what that function does with that string and how it gets the categories from that. If it is pulling categories based upon a DB attribute then one solution is to change categories 1-7 to have the attribute "portfoliocategory1" and categories 6 & 7 to have the attribute "portfoliocategory2". Then just pass "portfoliocategory1" or "portfoliocategory2" based on which sets of categories you want. Quote Link to comment https://forums.phpfreaks.com/topic/268855-php-wordpress/#findComment-1381398 Share on other sites More sharing options...
borisdollar Posted September 27, 2012 Author Share Posted September 27, 2012 Interesting. That may be a plan! Will take a look now and let you know how I get along. Many thanks for the reply. Quote Link to comment https://forums.phpfreaks.com/topic/268855-php-wordpress/#findComment-1381430 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.