Forum

Thread tagged as: Question, Problem

Filter Twice - Can you filter inside a template - content already filtered in pa...

We have setup the prev / next on a page with listing and detail view as per example recently posted: https://solutions.grabaperch.com/architecture/how-do-i-link-prev-next

The complexity comes about from how our gallery is setup, on one page, with 4 subcategories in this gallery that load inside divs that are hidden / fade on etc inside page, without navigating away.

The only issue we have, is that arrows to navigate to other items are loading on the page. So one item detail has 4 sets of arrows loading at the bottom or over the top.

So assume we need some kind of filter inside the prevnext.html template to only show arrows to other items if the slug matches the content region. As per how the filter is setup on $result = perch_content_custom array - although not sure how to add or if this would work - we did try...

Thanks for any help!

Stuart Farrell

Stuart Farrell 0 points

  • 7 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Are you asking if you can use multiple filters? See "Filtering by multiple fields": https://docs.grabaperch.com/docs/content/perch-content-custom/

Sorta I guess.... thought it might be an additional IF statement inside template.

So we can use this on the arrays you setup for prev/next?? Not sure filtering by slug here will get the result I want but can try.


perch_content_custom('XXX', array( 'template' => 'prevnext.html', 'filter' => '_order', 'match' => 'gt', 'value' => $result[0]['_sortvalue'], 'sort' => '_order', 'sort-order' => 'ASC', 'count' => 1, ));

AND


perch_content_custom('XXX', array( 'template' => 'prevnext.html', 'filter' => '_order', 'match' => 'lt', 'value' => $result[0]['_sortvalue'], 'sort' => '_order', 'sort-order' => 'DESC', 'count' => 1, ));

???

Drew McLellan

Drew McLellan 2638 points
Perch Support

I can't answer your question, as it's not clear what you're trying to do.

I'm trying to stop the output of the navigation arrows of other regions in the other divs on the page. The lists for these other divs are not loading, only the navigation arrows - which is why (I assume) need to filter the prevnext.html template or the array by the slug??

The four div's have the code to list and load detail view and use unique string name and unset variable call. Everything works fine, except for the navigation arrows for detail view to link to next/pre item. All the other div navigation arrows are loading on page no matter what detail item is showing...

PHP page code:


<!--Real Weddings--> <?php perch_content_create('Weddings', array( 'template' => 'weddings_detail.html', 'multiple' => true, 'edit-mode' => 'listdetail', )); if (perch_get('s')) { // Detail mode echo '<div class="back-share-link"> <a href="wedding-photography-gallery.php" title="Back">Back</a> <span><a href="#" title="Share">Share</a></span> </div> <div class="detail">'; $result = perch_content_custom('Weddings', array( 'template' => 'weddings_detail.html', 'filter' => 'slug', 'match' => 'eq', 'value' => perch_get('s'), 'count' => 1, 'skip-template' => true, 'return-html' => true, )); perch_content_custom('Weddings', array( 'template' => 'prevnext.html', 'filter' => '_order', 'match' => 'gt', 'value' => $result[0]['_sortvalue'], 'sort' => '_order', 'sort-order' => 'ASC', 'count' => 1, )); PerchSystem::set_var('is_prev', true); perch_content_custom('Weddings', array( 'template' => 'prevnext.html', 'filter' => '_order', 'match' => 'lt', 'value' => $result[0]['_sortvalue'], 'sort' => '_order', 'sort-order' => 'DESC', 'count' => 1, )); echo $result['html']; } else { // List mode perch_content_custom('Weddings', array( 'template' => 'weddings_listing.html', )); } ?> </div> <!--Popular Venues--> <?php perch_content_create('Popular-Venues', array( 'template' => 'popular_venues_detail.html', 'multiple' => true, 'edit-mode' => 'listdetail', )); if (perch_get('s')) { // Detail mode PerchSystem::unset_var('is_prev'); echo '<div class="detail">'; $resultpv = perch_content_custom('Popular-Venues', array( 'template' => 'popular_venues_detail.html', 'filter' => 'slug', 'match' => 'eq', 'value' => perch_get('s'), 'count' => 1, 'skip-template' => true, 'return-html' => true, )); perch_content_custom('Popular-Venues', array( 'template' => 'prevnext.html', 'filter' => '_order', 'match' => 'gt', 'value' => $resultpv[0]['_sortvalue'], 'sort' => '_order', 'sort-order' => 'ASC', 'count' => 1, )); PerchSystem::set_var('is_prev', true); perch_content_custom('Popular-Venues', array( 'template' => 'prevnext.html', 'filter' => '_order', 'match' => 'lt', 'value' => $resultpv[0]['_sortvalue'], 'sort' => '_order', 'sort-order' => 'DESC', 'count' => 1, )); echo $resultpv['html']; } else { // List mode perch_content_custom('Popular-Venues', array( 'template' => 'popular_venues_listing.html', )); } ?> </div> <!--Destinations--> <?php perch_content_create('Destinations', array( 'template' => 'destinations_detail.html', 'multiple' => true, 'edit-mode' => 'listdetail', )); if (perch_get('s')) { // Detail mode PerchSystem::unset_var('is_prev'); echo '<div class="detail">'; $resultd = perch_content_custom('Destinations', array( 'template' => 'destinations_detail.html', 'filter' => 'slug', 'match' => 'eq', 'value' => perch_get('s'), 'count' => 1, 'skip-template' => true, 'return-html' => true, )); perch_content_custom('Destinations', array( 'template' => 'prevnext.html', 'filter' => '_order', 'match' => 'gt', 'value' => $resultd[0]['_sortvalue'], 'sort' => '_order', 'sort-order' => 'ASC', 'count' => 1, )); PerchSystem::set_var('is_prev', true); perch_content_custom('Destinations', array( 'template' => 'prevnext.html', 'filter' => '_order', 'match' => 'lt', 'value' => $resultd[0]['_sortvalue'], 'sort' => '_order', 'sort-order' => 'DESC', 'count' => 1, )); echo $resultd['html']; } else { // List mode perch_content_custom('Destinations', array( 'template' => 'destinations_listing.html', )); } ?> </div> <!--Celebrity--> <?php perch_content_create('Celebrity', array( 'template' => 'celebrity_detail.html', 'multiple' => true, 'edit-mode' => 'listdetail', )); if (perch_get('s')) { // Detail mode PerchSystem::unset_var('is_prev'); echo '<div class="detail">'; $resultc = perch_content_custom('Celebrity', array( 'template' => 'celebrity_detail.html', 'filter' => 'slug', 'match' => 'eq', 'value' => perch_get('s'), 'count' => 1, 'skip-template' => true, 'return-html' => true, )); perch_content_custom('Celebrity', array( 'template' => 'prevnext.html', 'filter' => '_order', 'match' => 'gt', 'value' => $resultc[0]['_sortvalue'], 'sort' => '_order', 'sort-order' => 'ASC', 'count' => 1, )); PerchSystem::set_var('is_prev', true); perch_content_custom('Celebrity', array( 'template' => 'prevnext.html', 'filter' => '_order', 'match' => 'lt', 'value' => $resultc[0]['_sortvalue'], 'sort' => '_order', 'sort-order' => 'DESC', 'count' => 1, )); echo $resultc['html']; } else { // List mode perch_content_custom('Celebrity', array( 'template' => 'celebrity_listing.html', )); } ?> </div>
Drew McLellan

Drew McLellan 2638 points
Perch Support

So you're saying that under some condition, you don't wish to display previous and next links?

What is that condition?

Yes, currently it loads 4 sets of prev and next links on the page for the detail view of one item. So we only want the pre next links to show with links to other detail items within that repeating region. (There are four different regions with repeating items).

Drew McLellan

Drew McLellan 2638 points
Perch Support

Test to see if you got a result before showing the previous and next links:

if ($result) {
   ... prev and next ...
}

Hmmm... I added to gallery page, but no joy.

Is this correct:


$result = perch_content_custom('Weddings', array( 'template' => 'weddings_detail.html', 'filter' => 'slug', 'match' => 'eq', 'value' => perch_get('s'), 'count' => 1, 'skip-template' => true, 'return-html' => true, )); if ($result) { perch_content_custom('Weddings', array( 'template' => 'prevnext.html', 'filter' => '_order', 'match' => 'gt', 'value' => $result[0]['_sortvalue'], 'sort' => '_order', 'sort-order' => 'ASC', 'count' => 1, )); PerchSystem::set_var('is_prev', true); perch_content_custom('Weddings', array( 'template' => 'prevnext.html', 'filter' => '_order', 'match' => 'lt', 'value' => $result[0]['_sortvalue'], 'sort' => '_order', 'sort-order' => 'DESC', 'count' => 1, )); } echo $result['html'];
Drew McLellan

Drew McLellan 2638 points
Perch Support

Does the echo $result['html']; output anything?

Yes. That part is all working fine, it's just the next/pre arrows from other regions that are outputting when we don't want them to.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Ok, so do you just need to reverse the logic?

I assume so... but thought we could have used some kind of IF statement on html template for arrows.

The complication has come about because we have 4 divs - each with this list/detail view. I used the below:

PerchSystem::unset_var('is_prev');

But the arrows till show on page underneath the current / active detail view. I guess because it's being pre rendered before page that the DIVs can't hide?

Drew McLellan

Drew McLellan 2638 points
Perch Support

Sorry, I don't follow your question.

One the one page, there is 4 arrays for a list and detail view, each in a DIV. Code was pasted at start of steam here...

The list and detail view is all working, the only problem is the DIV's that are not "active" are still displaying their arrows for pre/next.

So I just need a way to hide these from outputting when the region they are related to is not displaying. The previous suggestion of wrapping in an IF statement didn't work.

Drew McLellan

Drew McLellan 2638 points
Perch Support

As I don't have the running code, all I can do is make guesses about what's wrong. This is really beyond the scope of what I can help you with.