We are transitioning over to a new forum platform. Please post new issues there. Existing threads will be dealt with here unless you choose to move them over. Visit the new forum

Forum

Thread tagged as: Question, Problem

Portfolio and Pagination

Hello I have developed a Portfolio, the pagination is done using the method given and I have limited a page to display xx number of items before paginating. So far so good.

Now my Portfolio uses a JQuery plugin to show and hide listings based on filters as I gave up trying to get the category filter to work driven by Perch.

Problem is that if you filter items, if some naturally fall say on page 2 of the "All" results, then thats where they stay when the filter is applied. So say in a grid of 9 items, even if there are only 5 items, 3 might fall on page 1 and 2 on page 2. Not ideal.

Is there something I could add to the pagination code to stop this? Or maybe turn off pagination when using the filters?

See the section here: http://dev.marketingalchemy.co.uk/portfolio/

Or is there a way to do this in Perch that will work?

Nigel Coath

Nigel Coath 1 points

  • 5 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Your jQuery code is filtering from the content on the page. To filter the full set of content, you need to start with it all on the page.

Yes thanks I suspected that was why, but that would make the "All" page potentially very long.

Is there a way to achieve this using Perch categories? Or a way to feed all the items to those filters without displaying them all?

Drew McLellan

Drew McLellan 2638 points
Perch Support

If you want the jQuery filtering, the best route is to write your pagination with jQuery too.

I am not so bothered about the filtering being jQuery, its just I could not get the Perch Category to work.

Could I achieve something similar within Perch? I already have the categories set up.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Yes, you can do that with categories.

So let me just clarify something, if done with Perch when you click on a filter link, would that have to go to a category page or would it just display within the same page?

As you know I struggled to get things to work before.

Drew McLellan

Drew McLellan 2638 points
Perch Support

You could set it up either way.

Unfortunately, I deal with so many people asking questions here every day that I can't keep track of who has done what before.

So I have this in my portfolio listing page:

<?php perch_content_custom('Portfolio', array(
    'template' => 'portfolio_listing.html',
    'paginate' => true,
    'page-links' => true,
    'page-link-template' => 'portfolio_links.html',
    'count' => 9,
    ));
?>

What do I need to do to filter by category inside this page and what do the links need to end up looking like to filter by these? I studied the solution and its geared towards using a category page. Stuck!

Drew McLellan

Drew McLellan 2638 points
Perch Support

If your category set was 'portfolio' and you had a category of 'brochures', for example, you'd filter them like this:

perch_content_custom('Portfolio', array(
    'template' => 'portfolio_listing.html',
    'paginate' => true,
    'page-links' => true,
    'page-link-template' => 'portfolio_links.html',
    'count' => 9,
    'category' => 'portfolio/brochures',
    ));

Thanks for tip, how would I code this so it changes on click of a link? And will this load inside the existing page without refreshing the whole page or is that not possible?

Rachel Andrew

Rachel Andrew 394 points
Perch Support

That would be achieved using JavaScript which really is outside the scope of the support here. I'd suggest asking on a forum that is focused on front-end development.

Okay I understand, what I want to ask is in your video it sounds like you can select the category via a link. But the above code is to hard code the category.

Do I need to make a page with above for each category e.g. brochures.php or is there a way to auto create this?

Rachel Andrew

Rachel Andrew 394 points
Perch Support

If you are back to wanting to filter from within Perch, rather than with JavaScript, then just pass into the array the category slug from the querystring instead of hardcoding it.

Where do I find the method to do this please, as the one on the Portfolio with Categories solution is fed from a separate page?

Rachel Andrew

Rachel Andrew 394 points
Perch Support

perch_get('s') will be the value on the QueryString (assuming the parameter is s), just as in the example.

You can't do it without reloading the page unless you do the filtering in JavaScript as Drew explained earlier in the thread.

Not sure what I have done wrong, I have this in portfolio.php

<?php
if (perch_get('cat')) {

// Filtered Mode
perch_content_custom('Portfolio', array(
    'template' => 'portfolio_listing.html',
    'category' => perch_get('cat'),
    'paginate' => true,
    'page-links' => true,
    'page-link-template' => 'portfolio_links.html',
    'count' => 9,
 ));

} else {

// Unfiltered Mode
perch_content_custom('Portfolio', array(
    'template' => 'portfolio_listing.html',
    'paginate' => true,
    'page-links' => true,
    'page-link-template' => 'portfolio_links.html',
    'count' => 9,
 )); 
}

?>

and in the category template:

<perch:category id="catTitle" type="smarttext" label="Title" required="true" />
<perch:category id="catClass" type="smarttext" label="Class" required="true" />
<perch:category id="catSlug" type="slug" for="catTitle" suppress="true" />

If I use this url as example: http://dev.marketingalchemy.co.uk/portfolio/?cat=brochures

It does not display an items.

If I hard code a category portfolio/brochures into list page it works.

What have I done wrong?

Rachel Andrew

Rachel Andrew 394 points
Perch Support

Cannot see any errors.

Can you confirm if the slug for the catSlug should be present and in which template, its inside the category_single template I am using to create Categories but confused as to whether its needed elsewhere?

Drew McLellan

Drew McLellan 2638 points
Perch Support

You need use a category path like my example. The category slug alone is not enough, because that category could appear in multiple sets.

Just to check then if I type this as a url: http://dev.marketingalchemy.co.uk/portfolio/?cat=portfolio/brochures

Then it displays the brochures category, so how could I get it to work without the portfolio in ?cat=portfolio/brochures