-
webfresh
I want to build a static page
It will have:
slider
query loop on custom post type for one category
query loop on custom post type for second category
slider
slider(sliders will be inserted by shortcode)
I could build this as a standard page and user query loop blocks.
BUT
I need the ‘Block Settings’ “remove container condition” option and this isn’t available in a GB container on a page, only in a container in an element block
What I did was create a query loop template element and put my two query blocks in there with the Block settings I need.
I assigned the query loop template to my static page
The query loops display fine.
My question is, is it OK to build out a whole page in a query loop template – i.e. add the slider elements in as well?
Note that I didn’t set the query loop to “Inherit query from template” but selected my custom post type parameter for each query loop block.
Otherwise I can see two other approaches:
1. Is there another way to achieve the ‘Block Settings’ “remove container condition” option when editing a static page.
2. Is there a way to insert a query loop template element (or other type of element) to where I want it on the page?
Thanks
-
Hi there,
if it’s a static page, then what would be the conditions that remove a container ?
As it may be easier to look at alternatives to resolve that issue. -
webfresh
the container is removed in the query loop
I have two custom fields in my custom post type.
The first one always shows
If the second one isn’t empty then I just want to put a hyphen (-) between the two fields. So if the second field is empty I don’t want the hyphen to showSo I am hiding the hyphen if the second post meta custom field is empty.
That is all working OK in my query loop template -
Does the hyphen need to be in the HTML ?
If not, and its just presentational you could add it using some CSS.Let me know
-
webfresh
Thanks David
That is an idea that could workHowever this is just a specific page.
I wonder if you could answer my original question:
Is it OK to build out a whole page in a query loop template – i.e. add the slider elements in as well? -
Fernando
Hi there,
If it’s a static page, you don’t need a Loop Template Block.
You can just simply add the Query Loop Blocks directly on the Page.
Or, do you want to build a template for multiple static pages?
If so, commonly a Content Template is used for this, but a Loop Template should work as well.
But, the caveat here is you’ll need a custom to alter the output of the Query Loops for every page if needed to be altered.
The more common practice is to add the content directly to the page.
-
webfresh
Thanks Fernando.
Maybe ‘static page’ is the wrong words to use.
What I meant is that it is a page I’m building. It isn’t a blog page or archive page.
I don’t need a template for multiple pages.
But I do want query loops on the page.
I want the feature:
‘Block Settings’ “remove container condition”
in my query loop
That feature isn’t available in a query loop added directly to a page. So that is why I don’t want to add the query loop directly to the page.
Only if the query loop is built in an element, is ‘Block Settings’ “remove container condition” available.
So I am trying to work out the best way to have the query loop in an element and add it to my page.
Obviously as David suggested I could do a workaround for the ‘Block Settings’ “remove container condition” using css, but I have other pages to build that may have a need for that setting as well in a different way.
As far as I can see I can build the whole page in a query loop template element and assign it to my page.
I’m mainly asking if there are likely to be any issues with this e.g. performance but also if there was another more obvious or logical way to add an element containing the query loop into my page in the correct place.
The ‘Block Settings’ “remove container condition” works well, is easy to maintain and obvious what it does (compared to adding css or php)
Thanks
-
Fernando
I see. Thank you for clarifying.
Using a Block Element to hook a Query Loop and utilize the “remove container condition” should cause no performance issues.
You can create a Portable Hook and hook your Block Element with the Query Loop anywhere. Creating a Portable Hook: https://generate.support/topic/create-a-shortcode-for-an-element/#post-38707
Alternatively, we can also use a WordPress filter to remove a Container if a certain meta data is not there.
An example of this for a Container with class –
remove-if-acf-field-name-testhello
is this:add_filter( 'render_block', function( $block_content, $block ) { if ( !is_admin() && ! empty( $block['attrs']['className'] ) && strpos( $block['attrs']['className'], 'remove-if-acf-field-name-testhello' ) !== false ) { if(! get_field('testhello', get_the_ID())){ return ''; } } return $block_content; }, 10, 2 );
You can also extend this code to cover multiple Containers in your static page.
-
webfresh
Perfect.
Thanks FernandoI’m getting the impression that these would be the better options rather than using query loop template
-
Fernando
You’re welcome!
If you go through that approach and need assistance with the code or something else, feel free to reach out!
- You must be logged in to reply to this topic.