Utilizing the jQuery code below for an accordion effect on all my WordPress posts on the front end.
(function($) {
function initAccordion() {
var $ele = $('.entry-content').hide();
$(".entry-header").unbind('click').click(function(e) {
e.preventDefault();
var $ele1 = $(this).parents(".post").children('.entry-content').slideToggle('fast');
$ele.not($ele1).slideUp();
});
}
initAccordion();
$(document.body).on('post-load', function() {
initAccordion();
});
})(jQuery);
Struggling to integrate the script with infinite scroll due to an issue that needs resolving.
Infinite scroll functions by automatically loading older posts as you reach the bottom of the page, which is functioning correctly.
The jQuery code provided operates by revealing one post when its title is clicked. The challenge arises when scrolling to a new page with infinite scroll, causing the open post to close automatically.
To witness this behavior, visit the Live example here. Try opening a post, then scrolling down until the URL changes to display .../page/2/
, resulting in the previously opened post closing.
Seeking guidance on preventing the closure of an open article when scrolling to a new page.