jquery返回按钮到可排序库中的上一个类别

I have a jquery portfolio gallery with 4 categories which are sortable. When you click on a category the portfolio is rearranged on the same page through jquery showing only those project in that category. Upon clicking a specific project the user can then see the project page/details. I want to add a back button on this page so that when a user is viweing a project they can return to category they were at before.

I tired the following which creates the back button but it take me back to the main portfolio page, not the category which I was browsing before.

function goBack() {
window.history.back();
}

This is one of the gallery page just in case: http://goo.gl/JeSNjD

Not knowing any of your application's code, this is a bit of a shot in the dark but I think I know what you're probably missing.

Using the history.back() will take you to the last page you visited (a page visit is only recorded if the URL is updated). If you are updating content in your website with jQuery and not loading a new page, your browser's history doesn't record this so back takes you back to the top page still.

What you will need to do is change your back button code to hide the current project, and redisplay the category page. You cannot use history.back().

Edit: If you need more data to correctly rebuild the previous page, you can either change the url for the category page (not necessarily simple to implement but perhaps the most robust thing to do), or to store information about what page they came from. If you are using cookies, you could save navigation there, but you could also add a ref value to the query string when you navigate to a project page.

Category page:

<a href="/home/projectName?ref=categoryName">Link to project</a>

Project page:

<a href="/home?category=categoryName">Back button</a>

Then use that information to reopen or resort your categories.

One problem is knowing which category a back button should return to. For example, /portfolio/foothill-pasadena-2 should route back to the office category and /portfolio/131house should route back to the Residential category. If I emailed you a link to one of those and you clicked it to go straight to the project page, should there be a back button on the page when you go to it and would it take you back to all categories or to the category related to the project?

One thing you could do is to change your permalink structure to include the category, such as /portfolio/office/foothill-pasadena-2 and /portfolio/residential/131house. Then your could hard-code your back button to go to /projects. You have some jquery running there (wp-content/themes/yourtheme/js/jquery.custom.js):

var isotopeContainer = jQuery('.portfolio-wrapper, .gallery-wrapper'),
isotopeFilter = jQuery('#filter'),
isotopeLink = isotopeFilter.find('a');
isotopeContainer.isotope({
    itemSelector : '.isotope-item',
    layoutMode : 'fitRows',
    filter : '.food-service'
});

isotopeLink.click(function () {
    var selector = jQuery(this).attr('data-category');
    isotopeContainer.isotope({
        filter : '.' + selector,
        itemSelector : '.isotope-item',
        layoutMode : 'fitRows',
        animationEngine : 'best-available'
    });
    isotopeLink.removeClass('active');
    jQuery(this).addClass('active');
    return false;
});

That is finding the four category links inside your filter div and adding a click function.

Maybe you can add some extra code that would get the document.referrer, checks it for a match against yoursite.com/new/projects/{category}/{project}, and pulls out the value of {category}. If the category matches one of your four values (food-service, office, residential, other), then call the click function on that element.