-
Stefanie
Hi team,
I am excited about the new overlay panels, they are great !!
I am considering building a query loop that, when the Read More button is clicked, does not display a new page (single post), but instead displays the content in an overlay panel.
I know this isn’t possible right now, but will this be possible in the future?
Thank you!
-
Hi Stefanie,
Why not? You can add the query block into the overlay panel and set an offset parameter for the query block to offset the posts that are already displayed in the regular content area.
Will that work in your case?
-
Stefanie
Hi Ying,
That would be fantastic if it were possible. But I suspect it’s not entirely clear what I mean.
I’ve created an example here. The button above the query loop triggers an overlay.
However, this overlay should not be triggered by the button, but by clicking on the individual cards in the query loop. The overlay should then display the content of the corresponding post.
In other words: I would like to build a content template for single posts that appears within the overlay panel.
It would be great if that worked.
Thank you!
-
Thanks for the site link, now I get what you are trying to achieve.
Unfortunately, I don’t think it’s possible to make the settings dynamic.
-
Stefanie
Thanks for your reply!
Too bad.
-
I get the idea, it’s pretty cool!
But it will require some custom JS and PHP, try chatGPT or Grok, they might be able to create a solution 🙂
-
Stefanie
try chatGPT or Grok
In principle, that’s a good idea. But I’ve now spent almost three hours with ChatGPT, and none of the solutions suggested by the AI work. In the end, we ended up in an endless loop, with ChatGPT repeatedly suggesting the same “solutions”, none of which work 😂
But maybe this feature will be available in the future. I think that would be cool.
Thank you!
-
Haha, sorry to hear that… But yes, your idea is very interesting.
I hope you can make it work 🙂
-
Stefanie
🙂 Thank you
-
The idea is too interesting to not go for it, so I did…lol
Try this:1. add CSS class
custom-looperto the looper block on the page.
2. add CSS classcustom-loop-itemto the loop item block on the page.
3. add CSS classoverlay-custom-looperto the looper block in the overlay panel.
4. add CSS classoverlay-custom-loop-itemto the loop item block in the overlay panel.
5. add this JavaScript to a custom HTML block on the page.<script> document.addEventListener('DOMContentLoaded', function() { const items = document.querySelectorAll('.custom-looper .custom-loop-item'); const overlays = document.querySelectorAll('.overlay-custom-looper .overlay-custom-loop-item'); if (!items.length || !overlays.length) { console.warn('No .custom-loop-item or .overlay-custom-loop-item found.'); return; } items.forEach((item, index) => { item.addEventListener('click', () => { // Remove active from all overlays overlays.forEach(o => o.classList.remove('active')); // Find overlay with matching index const target = overlays[index]; if (target) { target.classList.add('active'); console.log(<code>Activated overlay index: ${index + 1}</code>); } else { console.warn(<code>No overlay found for index ${index}</code>); } }); }); }); </script>6. add this CSS:
.overlay-custom-looper .overlay-custom-loop-item { display: none; } .overlay-custom-looper .overlay-custom-loop-item.active { display: block; }Note:
1. do not add any links to the loop item on the page, just use#as the link.2. the 2 query blocks (in the page and overlay) should display the same posts in the same order.
3. the simple solution only works for one page layout.
-
Stefanie
WOW, that sounds promising 👍
And the approach is much simpler than anything ChatGPT suggested 🙂But for some reason, it doesn’t work in my case. The overlay doesn’t appear when I click on a card. The backdrop is shown, but not the panel itself.
What I did:
1. I duplicated the query from the page and put it in an overlay.
2. Then I named the CSS classes as you suggested.
3. And I added the JS and CSS.
4. On the page: Here I changed the loop item from<div>to<a>and for the link I entered #.
5. On the page: I selected the new overlay panel as the trigger.But I must have done something wrong.
When I click on a card, the console reports: Empty string passed to getElementById()Do you have any idea why that is?
Thank you!!!
-
Can you provide an admin login so I can see the setup?
-
Stefanie
Thank you very much, Ying.
The login credentials are in the private field. -
There was a syntax error in the JS, I’ve corrected it.
It’s working now, please check.
-
Stefanie
Soo cooool 🙂👍🌷
That’s actually a nice and lightweight solution, and I think there will be many scenarios where this feature can be used. Great!
One more question: you write above:
3. the simple solution only works for one page layout.
Do you mean that it can only be used once per site? So if, for example, I also want to show the posts of a CPT in an overlay, it won’t work anymore?
Background of my question:
To improve the layout in the overlay, I created a new pair: new page and new overlay.
In both, I renamed the classes (.new-overlay-custom-looper, etc.). And, of course, on the new page, I selected the new overlay for the trigger.This works wonderfully, and the loop item in the new overlay no longer has the same design as the loop item on the page.
But I actually had to deactivate the old overlay (set it to draft) for it to work.
Because otherwise, the old overlay is called up when I click on a card in the new page.
I can’t explain it, because the names of the classes are different and the trigger for the cards is also different! But something seems to be getting in the way.
What do you think, does it only work with one instance on the site?
-
Do you mean that it can only be used once per site?
No, you can use it on as many pages as you want 🙂
I meant the query loop cannot have pagination, because the solution grabs the index of the post, it gets confused when pagination is involved.
Because otherwise, the old overlay is called up when I click on a card in the new page.
This is a weird one, I feel like it’s an overlay issue. But I can not replicate it on my install.
Do you have server-level cache on? It might be related to cache.
- You must be logged in to reply to this topic.