Tagged: sidebar widget
In the sidebar widgets, we have it set up to display the items within the same category as the main item on the page. Is there a way to prevent that current page/item from appearing in list of items in the sidebar widget?
I searched the forums for an answer using various keyword combinations but couldn’t find anything specifically relevant…
This happens with Portfolio items, but also more generally…
Thanks!
Hi,
Can you please create us a WordPress administrator account? post it here as a private reply.
Regards,
Josue
I thought I had replied already here…
We’re also having a problem editing any content inside a 4/5 column element within the Advanced Layout Editor on page indicated below in private
Thanks!!
Hi!
We added this code in the functions.php file:
add_action('pre_get_posts', 'ava_exclude_widget_post');
function ava_exclude_widget_post($query) {
if (is_singular('portfolio')) {
$exclude = avia_get_the_ID();
$query->set( 'post__not_in', array($exclude) );
}
}
Regards,
Ismael
Thanks Ismael – if I wanted to make sure that the Posts behave the same way, I’m assuming I’d just modify the if statement like so: (?)
if (is_singular('portfolio') || is_singular('post'))
?
Hey!
Yes, I think that will do it. Please use this code instead:
add_action('pre_get_posts', 'ava_exclude_widget_post');
function ava_exclude_widget_post($query) {
if (!is_admin() && is_singular('portfolio') || is_singular('post')) {
$exclude = avia_get_the_ID();
$query->set( 'post__not_in', array($exclude) );
}
}
We added the is_admin conditional so that it won’t affect the dashboard.
Best regards,
Ismael