-
Notifications
You must be signed in to change notification settings - Fork 843
Infinite Scroll: Improved rendering callbacks w/ WooCommerce support #9120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Infinite Scroll: Improved rendering callbacks w/ WooCommerce support #9120
Conversation
Previously, if you ran `is_main_query`, it would return false during the `pre_get_posts` hook because `is_main_query` compares the current query to the global. By setting to global first, these checks can be done correctly.
…own renderers without conflicts.
… is not inherited from main query
zinigor
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great! Testing this, looks like it really fixes the old IS problem with custom post types and sorting. Well done!
|
Added a commit to fix a theme conflict reported by @jeffikus and .com themes. |
|
Thanks @mikejolley busy testing now. |
|
Update: |
Adds basic WooCommerce support in the 3rd party scripts directory for WooCommerce.
This branch was branched from #9112 which will need reviewing and merging first.
The following changes are all related to WooCommerce and other plugin compatibility and are hence grouped into this single PR.
Posts per page changes
The current system is quite odd; it uses a fixed number of 7 or the 'posts per page' setting in WP Admin. This isn't suitable for custom post types where they have their own posts_per_page setting or preference. WC is a perfect example whereby posts_per_page is set to match our products grid.
To make this more robust we pass through the posts per page setting from the original query and use this instead.
If the theme defines a different
posts_per_pagevalue, we can default to that.Render callbacks
The previous system relied on a setting, and a fallback, for the render callback. One could also use
infinite_scroll_renderaction.There are a few problems with this:
infinite_scroll_renderaction, and the only way to prevent other callbacks outputting things is toremove_actionOur solution is to have a filter of registered callbacks which get ran in sequence. If a callback returns nothing (perhaps wrong post type is being shown?), it continues to the next until content is returned. Callbacks registered through theme support are still called, and the final fallback is the default
rendermethod in infinite scroll class.The filter is
infinite_scroll_render_callbacks. So example use:With this example it would call the following functions/methods in this order until content is returned:
my_post_render_callback()my_product_render_callback()add_theme_supportThe_Neverending_Home_Page::render()WooCommerce compatibility
All we need to do on this side is use the correct template for the content and render our wrappers. This should be fairly standard to any theme.
jetpack_woocommerce_infinite_scroll_renderdoes the rendering of this loop, andjetpack_woocommerce_infinite_scroll_render_callbackregisters this renderer using the system outlined above.jetpack_woocommerce_infinite_scroll_stylesimply hides the default numbered pagination WooCommerce outputs with CSS.