Join our HiFi mailing list to receive the latest news & updates

A jQuery Portfolio Plugin that's Interactive and Filterable

88 Comment(s) | Posted | by Joel Sutherland | |

Update: Since this post was written, we have rebuilt the New Media Campaigns website.  There still is a filtering portfolio, but it is now based on the jQuery isotope plugin.  This is a much better plugin however it does cost $40 for commercial use.  The plugin below still works great, but it doesn't animate quite as nicely.

 

See a Demo

Read The Documentation

Download the Plugin and Zip

Last week we finally launched our new site design. One of our favorite new features is our filtering portfolio. We've selected 50 of the websites we've done to be featured and we've categorized each one. Using jQuery, it is possible to filter through the big list to see sites that apply to certain categories. Feel free to test it out and sort through it here.

Some of the requirements we had when we built it were:

  • It should be easy to update
  • Each item should be able to be in multiple categories
  • We should be able to link to certain filters with a url hash

To get this done, Josh, Eli and I collaborated on different aspects. We've finally finished it up and wrapped it up in a plugin that can be used by anyone. To download a zip with the plugin, see the bottom of this post.

Documentation

Markup

The plugin is configurable to work with just about any markup. Here is an example of what we used for the filters and the portfolio items.

Filters


Portfolio Items

  • Saranac

  • ...

Of course the markup can be completely arbitrary. All of the styling is done in css. There are only two major requirements:

  1. Linking Filters to Items - The hashed href of the filter link must match the class of the portfolio item. In the example above, the #jquery filter matches the last class of the only portfolio item.
  2. Portfolio Items are Wrapped - As you'll see in the JS section below, the plugin is called on a wrapper of the portfolio items. In this case, the wrapper is the
      .

Javascript/jQuery Setup

The jQuery is really simple to set up. If you use the same markup as I have, you can even leave out the settings and it should work out of the box. Simply do the following after you have included the filterable plugin:

$(document).ready(function(){
	$('portfolio-list').filterable();
});

The plugin will also take a number of optional parameters. These are the defaults:

settings = $.extend({
	useHash: true,
	animationSpeed: 1000,
	show: { width: 'show', opacity: 'show' },
	hide: { width: 'hide', opacity: 'hide' },
	useTags: true,
	tagSelector: '#portfolio-filter a',
	selectedTagClass: 'current',
	allTag: 'all'
}, settings);

To change any of the defaults, just pass them in to the initial call:

$(document).ready(function(){
	$('portfolio-list').filterable({
		animationSpeed: 2000,
		show: { height: 'show' }
		useTags: false,
		etc...
	});
});

Fun Features

Adding a Hash to a Url

If you have the useHash setting enabled, you can link directly to a single filter. You can see this in effect on our portfolio by visiting http://www.newmediacampaigns.com/section/portfolio#jquery.

Exposed Events

Once filterable() has been called, there are a number of events that get bound to the wrapper. Here they are:

/* Handles the state of the filter buttons as well as the portfolio items
 * Expects "tagToShow" to include a hash. */
$(this).bind("filter", function( e, tagToShow ){});

/* Just switches the portfolio items.  Expects a class name */
$(this).bind("filterportfolio", function( e, classToShow ){});
			
/* Shows a tag in addition to those being shown - expects a selector */
$(this).bind("show", function( e, selectorToShow ){});
			
/* Hides a tag - expects a selector */
$(this).bind("hide", function( e, selectorToHide ){});

The most useful of these is the first. It will allow you to programatically change the state of the filters and portfolios. So lets say you have a link somewhere on a page that you want to use to make sure your jQuery tag is shown. You could code something like the following:

$(document).ready(function(){
	$('portfolio-list').filterable();
	$('#linkID').click(function(){
		$('portfolio-list').trigger('filter', [ '#jquery' ]);
	});
});

For more details about these exposed events, feel free to check out the source or ask a question in the comments. If you're ready to test it out, just check out the zip below.

Download the Zip

To download this plugin and a sample project, click here.

To see the sample project first, click here.

88 Comment(s) | Posted | by Joel Sutherland | |

Comments

  1.  Xavier's avatar
    Xavier
    | Permalink

    Wow! It's a wonderful work!! Thanks for sharing!

  2.  Joel Sutherland's avatar
    Joel Sutherland
    | Permalink

    @Xavier: Thanks! I like the illustration on your site.

  3.  James's avatar
    James
    | Permalink

    Would it be easy to provide multiple tags for items so a user could make multiple selections?

    e.g could a user choose shoes (show all shoes), then choose red?

  4.  dlv's avatar
    dlv
    | Permalink

    great! it's really useful, easy and shiny way to filter items!!
    I read others jquery filter scripts, but this is more easy and better explained than others

    thanks for share !!!
    to bookmarks

  5. ovaxio's avatar
    ovaxio
    | Permalink

    Oh thank you, i just find your script and it is exactly what i need :) Really good job.

  6.  Emrah's avatar
    Emrah
    | Permalink

    Thanks.

  7. nachomaans's avatar
    nachomaans
    | Permalink

    Thank you for the script and clear explanations!

    We are using a tweaked version here: http://www.id3.co.th
    (and you are credited here: http://id3.co.th/copyright.php)

  8. ELCODIGODEBARRAS's avatar
    ELCODIGODEBARRAS
    | Permalink

    It´s a really beauty jquery plugin code;clear explanations, and very useful and elegant resource.

    Thanks for sharing with us your knowledge and code skills; with this action we are getting an internet more friendly for all.

    Thanks again !

  9. Joel Sutherland's avatar
    Joel Sutherland
    | Permalink

    @nachomaans

    Thanks for the callout!

    @Elcodigodebarras

    Thanks for the complements. Let me know when you get it launched.

  10. Chris's avatar
    Chris
    | Permalink
  11. Keiron Roberts's avatar
    Keiron Roberts
    | Permalink

    Great plugin.

    Like James asked (July 22, 2009) is there an easy way to have multiple options so a user could select an option in one list to reduce the images and then another option in a second list to further filter the images, and then again (and again) until they reduce it to a very small gallery.

  12. Joel Sutherland's avatar
    Joel Sutherland
    | Permalink

    Keiron,

    The issue is not the code difficulty, but the UI. When multiple categories are selected should it do an AND as you suggest, or an OR? How should this be shown in the filters?

  13. joseph Jin's avatar
    joseph Jin
    | Permalink

    thank you take us so better tutls, i read this post "Creating a Filterable Portfolio with jQuery" (http://net.tutsplus.com/tutorials/javascript-ajax/creating-a-filterable-portfolio-with-jquery/), inspired both!

  14. chetan's avatar
  15. Pancho's avatar
    Pancho
    | Permalink

    Joel, script is great. I have implemented it to my portfolio.
    But i have one big problem.

    I heve added a hover function to portfolio elements. And when portfolio is sorted (animation of width), hover animation stop sorting animation.

    The second one is:

    $(document).ready(function() {
    $('ul.portfolio-list li').hover(function() {
    $(this).siblings().stop().fadeTo(500,0.7);
    }, function() {
    $(this).siblings().stop().fadeTo(500,1);
    });
    });

  16. jonath's avatar
    jonath
    | Permalink

    This was what I've been looking for so long. Pretty impressive and easy to implement.

  17. Chris Beaman's avatar
    Chris Beaman
    | Permalink

    This looks great. Pending easy implementation, I plan to use this for my own portfolio. Please check here sometime in the next month or two for some linklove: http://www.chrisbeaman.com/credits

  18. nashekrashe's avatar
    nashekrashe
    | Permalink

    Thanks for sharing. Filter works great.

  19. run's avatar
    run
    | Permalink

    please, we would terribly need a solution with pagination of the filterd ( and unfiltered)
    content.

    we have over 300 items in our portfolio!

    thanx in advance

  20. Nathan Dailo's avatar
    Nathan Dailo
    | Permalink

    Hi,

    I was just wondering if there was a way to implement this into WordPress? Im working on a project that needs to emulate the filtration function of this link http://www.dalealcock.com.au/New-Homes/#/Content/New-Homes/Browse-Tool - It needs to display the filtered products without having to reload the page. Any ideas?

    Kind regards,
    Nathan Dailo

  21. Xander's avatar
    Xander
    | Permalink

    I've incorporated this into my websites portfolio, using wordpress query_posts, but it only shows 10 items out of the Portfolio category. any idea as to why the limit would be on 10?

  22. Xander's avatar
    Xander
    | Permalink

    Nevermind, solved my problem, forgot to put in showposts= into the loop

  23. James's avatar
    James
    | Permalink

    Has anyone managed to get multiple filters working with this?

    I am trying to have a second menu appear once you select the first filter, and in answer to Joels question, this is an AND select...

    I basically want to break a list down by Area, then Country, then type of Service...

    Anyone got any ideas?

    Cheers

    Jim
    http://www.thetwopercent.co.uk

  24. Raghib suleman's avatar
    Raghib suleman
    | Permalink

    Thanks for sharing this project cooooooool!

  25. Krystian's avatar
    Krystian
    | Permalink

    This looks awesome. Is it possible to filter the content by more than one category?

  26. Aaron Fooshee's avatar
    Aaron Fooshee
    | Permalink

    Nice interface. I like the concept and implementation so far.

    I used some of your code on a project and thought the hashtags didn't work for a while. Trying to navigate to a anchor via the address bar while already on filterable.html (with any anchor) does nothing, but it does work if you are not on filterable.html already. Would be nice to have it check for changes and submits in the address bar.

    Either way, thank you for the ideas and code.

  27. Joel Sutherland's avatar
    Joel Sutherland
    | Permalink
    Krystian, Yes it is possible but it requires changing the plugin source. The issue is that you need to either specify ANDing or ORing between selected categories.
  28. Jesse Kaminski's avatar
    Jesse Kaminski
    | Permalink
    This was amazing, just what I was looking for! Thank you!
  29. CyberFox's avatar
    CyberFox
    | Permalink
    Filtering with Masonry! http://www.kenya-schools.com/
  30. Phil S's avatar
    Phil S
    | Permalink
    I'm also trying to do what Krystian is doing. I have a portfolio item that falls into multiple categories. When I sort, it will only be shown if the hash tag matches the first element. I see you mentioned and or'ing any ideas?
  31. Jason Day's avatar
    Jason Day
    | Permalink
    I'm getting - "$ is not a function" when I try and use this with wordpres...thoughts?
  32. seularts's avatar
    seularts
    | Permalink
    I have a problem, when I load the script (in firefox), my favicon disappears. What can I do about it!?
  33. Jepser's avatar
    Jepser
    | Permalink
    Hi! Pretty cool tutorial, I have one question, as you mentioned that we have to make an OR or AND connection between multiple categories... I mean (for example).

    I sell cars, my categories will be the brands, I select BMW but then I want to show only the sedan (and I have other subcategoies) or I want to check all send type cars (no matter the brand)...

    Ehat piece of code do I change, I want an AND connector.

    Thanks!
  34. steven costello's avatar
    steven costello
    | Permalink
    Thanks for this but I have a problem. Im trying to use my sub nav to link to a specific category, and it works if you on a different page like home.php. but if your on the portfolio page it doesn't change them, Its not a major problem Just a bit weird.

    Thanks,
    Steve C
  35. Alex's avatar
    Alex
    | Permalink
    Very nice, thank you!
  36. Jon's avatar
    Jon
    | Permalink
    Hey guys! This is great! I was just wondering how I could use a scale animation instead of height or width. So, it would kind of look like the quicksand plugin animation. (http://razorjack.net/quicksand/).

    Thanks for the awesome plugin. I will definitely link to this from my site!
  37. Alex's avatar
    Alex
    | Permalink
    I'm using this plugin for the frontpage of a site. The filterable listings are abstracts of the subpage. If you enter the subpage and try to switch back to the frontpage with the navigation, all items get display: none;

    After clicking again on the same filter-tag you get the items listet.

    Any ideas why the plugin sets all items to display: none when you come from the subpage?

    Best regards
  38. Lee's avatar
    Lee
    | Permalink
    Is there any way to use the rel tag rather than a class so if javascript is not on at least the navigation would work if the href pointed to an actual page ?
  39. Joel Sutherland's avatar
    Joel Sutherland
    | Permalink
    Lee,

    This should easily be possible by opening up the plugin code and using .attr('rel') instead of .class().
  40. pama's avatar
    pama
    | Permalink
    hi,

    i have some problems with this

    When i click on items noting happens

    Any help? Thanks
  41. Moonwalker's avatar
    Moonwalker
    | Permalink
    Hi Joel,

    Thanks for the great script. I'm loving it. :)

    Just one question though. Is it possible to not use the anchor "#" in the address? Just a click function can do the magic?

    I'm asking this because I use Mod_rewrite on my server, and as you probably know anchors doesn't work when mod_rewrite is on. I'm still trying to find out a solution for this problem.

    Thanks in advance.

    mw
  42. Rishi Patel's avatar
    Rishi Patel
    | Permalink
    Great script!

    One Question:
    I tried to put a lightbox effect on the items, but the lightbox script cancels out the filterable script. Has anyone gotten this to work, and if so, what am I missing?

    Thanks in advance,

    Rishi Patel
  43. Raghibsuleman's avatar
    Raghibsuleman
    | Permalink
    very good work....
  44. ste's avatar
    ste
    | Permalink
    hi guy, how I shold to use the plugin firterable?
    I'm new in this...
  45. Lukas's avatar
    Lukas
    | Permalink
    Hi all,

    I would like to use this script together with some other anchor tags on the same page.. But that doesn't seem to work.
    Does anyone know how I could fix this? I'll probably have to change some javascript?

    Regards,
    Lukas
  46. Memur's avatar
    Memur
    | Permalink
    thanks. it was a good article about jquery. i has been searching that on every sites.
  47. creative web design's avatar
    creative web design
    | Permalink
    This is a very interesting project, I like this effect. I will definitely use the code from this example in the future. Thanks for the files.
  48. Muhammad Faisal's avatar
    Muhammad Faisal
    | Permalink
    Hi all,

    Its a great plugin, its effect it amazing. i want to implement this in one of my site. but the problem is that i also want to add a class (etc '.last') to every 5th li item of this portfolio to clear any right-margin on last item of every row. But i dont know how to implement this.

    Does anyone know how can i do this?

    Regards
  49. ASK Technologies's avatar
    ASK Technologies
    | Permalink
    Nice work,Great post,I ll use it for my projects,Thanks
  50. stephan's avatar
    stephan
    | Permalink
    Hi all,

    First of all, its a great plugin!!
    But I dont know much about jquery but how can i modified this plugin....?

    I want no animation on the projects but if i click on a subject class, the project must stand there immediately.

    Can anybody help me please?

    Kind regards
  51. Thomas Griffin's avatar
    Thomas Griffin
    | Permalink
    Hi,

    This is an excellent plugin! I absolutely love it! I wanted to see if it would be possible to somehow hide everything on the page load, and then once you select a category, then the category will be displayed. So instead of the original page loading with #all, I would want it to load with #null or something to that effect in order to hide everything. Then the people can choose between categories if they so wish.

    Thanks,
    Thomas
  52. Kevin Hughes's avatar
    Kevin Hughes
    | Permalink
    Great plugin! I was hoping you could help me out though--as near as I can tell the markup and JS are fine (pretty much based off your files) but for some reason the filters won't call the specified images at all.. am I missing something really simple here?

    Sample site is up at www.kevinhughesdesign.net/brandlab
  53. Joel Sutherland's avatar
    Joel Sutherland
    | Permalink
    Kevin,

    JQuery is not loading on that page. (404 error).

    I suggest using a tool like Firebug while developing to help catch things like this.
  54. Ahmad's avatar
    Ahmad
    | Permalink
    Very nice plugin but I have a question which was asked above and not answered.

    When my main page gets loaded. I don't want to show all the items. Just a specific page. For example I want 10 pages to show 10 items per page and while it is loaded for the first time, page 1 gets loaded with its relevant 10 items. Right now I have like 50 Items and all the page is filled up with it. Any solution please??
  55. Gregg's avatar
    Gregg
    | Permalink
    Hey, great plugin! I'm using it for a real estate listing site and have it working pretty well. I'm wondering a couple of things:

    - Is it possible to have "no results" text appear if someone selects something that has no content? I can of course take it off the menu, but that would require ongoing updating. Would prefer some kind of text appear.

    - Is it possible to not display a specific class of items by default. i.e. show all EXCEPT a specific class.

    THANKS!
  56. ILLNeSs's avatar
    ILLNeSs
    | Permalink
    Hello so I'm using this plugin on my website currently, It works fine in safari, google chrome, IE, Firefox 3.6....

    i recently updated to firefox 5 and the filters all of a sudden don't work any more in the browser.

    any suggestions as to what is causing this? and maybe how i can go about fixing this?

    www.illness-illustrated.com (not sure why but it kept telling me my site was not valid in the comment section)
  57. DG's avatar
    DG
    | Permalink
    Hey guys,

    awesome script!

    One question: Is it possible not to show "all" on the first page landing. I want to show a other category?!

    thanks
  58. Maikel's avatar
    Maikel
    | Permalink
    Hi Joel,

    Great tutorial, just what I was looking for. Maybe I wil create a WordPress plugin with your script, so everybody can insert it in his or her WordPress with just a few clicks.
  59. Articulos Promocionales's avatar
    Articulos Promocionales
    | Permalink
    Great tutorial, just what I was looking for.
  60. Xavi Ivars's avatar
    Xavi Ivars
    | Permalink
    Hi Joel,

    I've found a very small bug in your code. It seems you can use any "id" to make the portfolio, but inside the javascript code, when setting up tags, "#portfolio-list" is hard-coded.

    I'm sure there will be most eficient ways to do it, but replacing

    /* ============ Setup Tags ====================*/
    if(settings.useTags){
    $(settings.tagSelector).click(function(){
    $('#portfolio-list').trigger("filter", [ $(this).attr('href') ]);
    $(settings.tagSelector).removeClass('current');
    $(this).addClass('current');
    });
    }
    with

    if(settings.useTags){
    t = $(this);
    $(settings.tagSelector).click(function(){
    t.trigger("filter", [ $(this).attr('href') ]);
    $(settings.tagSelector).removeClass('current');
    $(this).addClass('current');
    });
    }

    does the trick ;)
  61. Wagner's avatar
    Wagner
    | Permalink
    Hi Joel,

    Thanks for the great plugin! Very easy to implement! I was just wondering whether would be possible to change the animation. If yes, how?

    Thanks and keep up with the great work!
  62. Shel's avatar
    Shel
    | Permalink
    Hi all,

    Great plugin!

    But it seems that many of us are having a problem with pagination (multiple page list for the different actegories or just the "all" page.

    I have over 400 items to use in this plugin but can you imagine what this would look like in the "all" page without pagination?
  63. Mike's avatar
    Mike
    | Permalink
    Is there a way to use this with a HTML tag?

    I've created a list of drop down menus that aren't playing too nicely on an ipad, so i am trying to implement your code using a select drop down instead. Any insight would greatly help out me. Much appreciated. BTW, I am pretty much a JS novice.

    Regards.
  64. Béla's avatar
    Béla
    | Permalink
    hy...
    sorry, my english is not very well :/

    but coul you explain me how i could get the easing effect to run?

    thank u very much!!!!!!!!

    greats
  65. Khalid's avatar
    Khalid
    | Permalink
    Hi there!

    This is a great plugin!! It also works after I created my own custom post-type. Just had a question and that's how to get it as smooth as you have it.

    Mine is only smooth in Internet Explorer. I hope someone can help me: http://kawani.kelkhouani.com

    Thank you so much!!
  66. Ty's avatar
    Ty
    | Permalink
    First off, excellent plugin — very nice work. I do have one question: is there a way to display a message if there are no results? For instance, I'm using the plugin for a realtor who has a number of filters (new construction, commercial, etc). The menu/filters will always remain static but the content will change; at times there may not be any commercial listings. In this scenario is there a method to display a message indicating there were no results found?

    Appreciate any feedback you can offer.
  67. abubakar's avatar
    abubakar
    | Permalink
    Thanks for this great work i have a problem and need help i want to show portfolio categories with sub categories like this http://www.megagamezone.com/wp-content/uploads/categorymenu.png can any one help me how to do this..

    thanks
  68. needhelp's avatar
    needhelp
    | Permalink
    This is a great portfolio tool!
    I would really like to use it in my wordpress website. Can someone please let me know how to install this plugin in wordpress?
  69. Alex's avatar
    Alex
    | Permalink
    how can i change the width & height of boxes ?? i want to show 250*183 instead of 164*120 ...
  70. Jeremy's avatar
    Jeremy
    | Permalink
    Hi Joel

    Is there a way to add a dropdown filter for the categories ?
  71. stefan's avatar
    stefan
    | Permalink
    Hey joel, hey guys,

    can anyone tell me how to change the animation like in the example poste here http://www.newmediacampaigns.com/portfolio#non-profit.

    I´m not so familar with Jquery, but i would like to use it in my portfolio site.
  72. web design nepal's avatar
    web design nepal
    | Permalink
    WOW thanks for the tutorial. I’ll be trying that out on my project. this would make a excellent featured slider, thanks!
  73. Travis's avatar
    Travis
    | Permalink
    Hi.

    I can't for the life of me get two portfolios to work on one page! I'm no jquery expert, but is this possible?

    Thanks!
  74. Mohammed Fellak's avatar
    Mohammed Fellak
    | Permalink
    thanks
    i like this Portfolio
    i'm asking if this Project is OpenSource
  75. zara's avatar
    zara
    | Permalink
    Hi ya is it possible to remove the all function from the js and if so how. x
  76. Andy GH's avatar
    Andy GH
    | Permalink
    Hello. Pretty nice tutorial. I have one weird behavior, I guess you could call it, where it only filters on refresh. Any suggestions on what is going on?
  77. Andy GH's avatar
    Andy GH
    | Permalink
    I forgot to mention that I this is on my website at http://www.aghdesigns.net I am using to filter between Web Design and Web Development.
  78. Jamie's avatar
    Jamie
    | Permalink
    Is there a support site for this plugin? I have seen other tutorials for this plugin and I can't get any of them to work. It only filters my images if I refresh the page after clicking the link
  79. Babatunde's avatar
    Babatunde
    | Permalink
    Wow!!! This is Simply Amaizing and SIMPLE!!! The Source Files Are Just Easy To Use!!! Bless You!!!! For This Post!!! It just saved me loads of time and stress!!!!
  80. مداحی's avatar
    مداحی
    | Permalink
    it was kind article.
    and the
    Best article for making filterable portfolio on the web.
  81. Agung Wiseso's avatar
    Agung Wiseso
    | Permalink
    Woow.. really thanks.. This is the script which I want to make a filter gallery..
  82. freelance web designer kerala's avatar
    freelance web designer kerala
    | Permalink
    Thanks...
  83. mrto2's avatar
    mrto2
    | Permalink
    can we use some other example of animation? Plz advice.
  84. Peter Cunningham's avatar
    Peter Cunningham
    | Permalink
    Wow, this is excellent. Exactly what I need for a wordpress site I am working on, however I know nothing about jQuery so would you be in a position to offer your services to me for a fee of course, to create a similar page for in on my client's wordpress site? Please email if you are interested, thanks.
  85. Ather's avatar
    Ather
    | Permalink
    This is a nice script you have posted. I have also developed a free jquery plugin which your readers might find useful http://www.nimble3.com/nimble-portfolio-free-filterable-jquery-porfolio-wordpress-plugin/
  86. Ben's avatar
    Ben
    | Permalink
    Hi Sir, refer to this sample, http://files.www.gethifi.com/posts/filterable/filterable.html#partner

    When click on the tab, may i know how to remove the moving animation?
  87. px's avatar
    px
    | Permalink
    yeah please, i want to remove moving animation too.
    i want exactly this effect: http://www.newmediacampaigns.com/portfolio

    Please joel, please.
  88. Tracy's avatar
    Tracy
    | Permalink
    Does anyone know if this works with multiple idSelectors? (I want to put multiple filterable nav bars on the same page).

Leave a Comment