June 23, 2019 at 6:35 pm #491863jrobertsMember
Hi! I'm very new to coding, but was wondering if anyone could help me with getting an if( statement to work in PHP.
Using the Lazy Blocks plugin, I've created a block ("Meta Information") that places meta data (authors, data etc.) in the body of the post.
Meanwhile, I'm using a StudioPress snippet -
remove_action( 'genesis_entry_header', 'genesis_post_info', 12 );
- to hide the naturally occurring meta data in the post.
The problem arises in that I don't want to apply this snippet to all of my posts. I have a huge backlog of posts for which it would be impossible for me to manually apply this information block in order to display the meta.
As a solution, I wondered if I could create an if( statement before, testing first whether the block exists before applying the snippet.
Unfortunately, i don't know how to refer to the block (or if it's even possible to refer to it) in an if( command.
Could anyone help with this? My own attempts at figuring out the block have all failed!http://exeposetest1.wpengine.com/June 23, 2019 at 6:54 pm #491866AnitaKeymaster
That might be a better question on the Lazy Blocks plugin support page. They could probably tell you how to target that.
Love coffee, chocolate and my Bella!June 24, 2019 at 5:36 am #491875Victor FontModerator
You're question is unclear and confusing. While I know that you understand what you're saying, to a reader, the way you reference blocks, snippets, and information without context will lead to wrong answers. For example:
The problem arises in that I don't want to apply this snippet (Assume you mean the remove post info) to all of my posts. I have a huge backlog of posts for which it would be impossible for me to manually apply this information block (What information block? There's no context) in order to display the meta (Assume Lazy Blocks).
As a solution, I wondered if I could create an if( statement before, testing first whether the block exists (What block? Lazy Blocks or Genesis post info?) before applying the snippet.
Unfortunately, i don't know how to refer to the block (Which block? Lazy Block or Genesis Post Info?) (or if it's even possible to refer to it) in an if( command.
The Genesis Post info details are not saved with the post content. It is rendered at run time as the post header is processed in the WordPress loop. There is nothing to reference until the content is fully rendered and ready to send to the browser. The only way to reference remove post info from a group of posts is to wrap your code in a WordPress conditional: https://codex.wordpress.org/Conditional_Tags
June 24, 2019 at 6:28 am #491877jrobertsMember
My apologies; I assumed that referring to "snippet" and "information block" would indicate the only snippet and information block I referred to in the question. Apparently not. The Genesis info itself isn't a block in Gutenberg, or at least as far as the editor would indicate.
Nonetheless, thank you for showing me WordPress conditionals. I might try to make the Genesis Post info appear only when the Lazy Block isn't present, though my question referred to the Lazy Block. I understand if this is a Catch-22, given that both are presumably rendered at the same time.
I've posted on Lazy Blocks support, to see if they can offer any more help!
- The forum ‘General Discussion’ is closed to new topics and replies.