Skip to content
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

theme can break post content blocks when used outside of the Loop #18

Open
itsnotlupus opened this issue Dec 14, 2024 · 0 comments
Open

Comments

@itsnotlupus
Copy link

First, I must apologize for only having a passing familiarity with modern PHP in general and WordPress in particular.

I've put together a template that includes a sidebar that uses a query loop to render a blurb of text ("Site News"). Since I want the entire news there, I'm using a "Content" block rather than the default "Excerpt" block within the Post Template subtree.
It works well enough on some pages, namely the ones that only render a single article, but breaks on pages that use a query loop themselves.
Specifically, the "Content" block in the sidebar renders the entirety of the first item return by the main query loop.
After pasting various error_log() lines across an unfamiliar codebase and narrowing things down, I'm left staring at wp-content/themes/wecodeart/inc/gutenberg/blocks/post/class-content.php, specifically these 3 lines in render():

            if ( ! in_the_loop() && have_posts() ) {
                  the_post();
            }

If I comment these out, my problem disappears, and the sidebar consistently loads its Site News correctly across the site.

I'm sure there's a good reason for those lines to be added from the base render_block_core_post_content() function, but perhaps there might be an additional check to throw in there that'd allow templates to render arbitrary post contents anywhere while keeping its intended purpose.

I hope that makes sense.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant