-
AuthorPosts
-
March 29, 2022 at 9:11 pm #1346477
On a portfolio page, the portfolio grid is present as a kind of index to quickly view of portfolio items. It’s set to show 6 items, however that includes the portfolio item that is displayed on the active page. Can the portfolio grid exclude the content on the current page so that it isn’t duplicated?
March 30, 2022 at 10:51 am #1346545Hey m,
Thank you for the inquiry.
You can use this filter in the functions.php file to exclude the current portfolio item from the grid element.
function avia_portfolio_query( $query, $params ) { if(is_single()) { $id = get_the_ID(); if(avia_post_grid::$grid == 0) $query['post__not_in'] = array($id); } return $query; } add_filter( 'avia_post_grid_query', 'avia_portfolio_query', 10, 2);
Best regards,
IsmaelMarch 30, 2022 at 2:46 pm #1346593Thank you. I tried this with the child folder functions.php file, but it broke the website.
March 30, 2022 at 3:25 pm #1346602can you try this instead:
function ava_exclude_current_post($query) { // you can use here aswell : if(is_single()){ if (is_singular('post') || is_singular('portfolio') ) { $exclude = avia_get_the_ID(); $query->set( 'post__not_in', array($exclude) ); } } add_action('pre_get_posts', 'ava_exclude_current_post');
March 30, 2022 at 3:59 pm #1346603Thank you. Same result.
March 30, 2022 at 6:15 pm #1346637but you are using a child-theme or where did you enter that snippet?
you can see that it is working on my installation : https://webers-testseite.de/portfolio/john-dietz-elektrotechnik/ … and pirol ( i did not change the rest of all portfolios.March 30, 2022 at 7:04 pm #1346645Yes, a child theme is used. I tried this with the child folder functions.php file.
March 30, 2022 at 7:08 pm #1346646that is correct. But you see that on my testpage all is ok.
Did you have on top of your child-theme functions.php that<?php
this introduction must remain above!
March 31, 2022 at 12:37 am #1346666Yes it is there. You can see it in the link provided.
March 31, 2022 at 9:42 am #1346719Hi,
Thank you for the update.
You have to copy the snippet directly from this forum, not from your email. The error occurs because some of the characters in the snippet have been converted to their html entity code.
Best regards,
IsmaelMarch 31, 2022 at 3:27 pm #1346752Perfect, thank you for this tip! The second set of code works brilliantly.
This can be closed.April 1, 2022 at 5:29 am #1346814Hi,
Glad to know it is now working! Copying code from your email and pasting it to the code editors converts parts of the snippet to something else, causing that error that you previously encountered. Just make sure to copy the snippets directly from the forum next time.
Let us know if there is anything else we can help you with.
Have a nice day.
Best regards,
Ismael -
AuthorPosts
- The topic ‘Can the Portfolio grid auto not show the portfolio item of the current page?’ is closed to new replies.