Jump to content

Php & Wordpress


Recommended Posts

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>';


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.



Link to comment
Share on other sites

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.

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.

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.