- This topic has 7 replies, 3 voices, and was last updated 6 months, 3 weeks ago by
David.
-
AuthorPosts
-
September 7, 2022 at 12:43 pm #2336345
Sascha
Hey there, I’d like to display the latest post of the CPT “Menu” in a section on frontpage and also under one menu-item on https://dev.diegarbe.de/menu. Any idea about how I can achieve this?
Thank you in advance and kind regards,
SaschaSeptember 7, 2022 at 7:26 pm #2336475Fernando Customer Support
Hi Sacha,
You can use a GB Query Loop Block. Reference: https://docs.generateblocks.com/article/query-loop-overview/
You should be able to query the latest post from your CPT with this.
September 7, 2022 at 10:24 pm #2336545Sascha
Sorry, my query was misleading:
I don’t want to “list” the latest post from “Menü” CPT, but to display it fully, including the styling. As if the post was fully “embedded”.
Is this possible?
By the way: the “Menü” CPT include custom fields (by MetaBox) for meal-names & meal-prices. The editor will always duplicate the post every week and enter new data into these fields, that’s why only the newest post should be embedded here. Reference site is this one, the new dev-site (where I try to accomplish this new menu feature) is this one.
Thank you in advance and kind regards,
SaschaSeptember 7, 2022 at 10:31 pm #2336548Fernando Customer Support
You can try using a Block Element – Hook.
Then add a Dynamic Content Block in your Query Loop.
September 9, 2022 at 1:04 am #2337728Sascha
Thanks, Fernando,
after following your advice and digging a bit deeper into how the Query Loop is functioning, I have a much better understanding about it, which is great!
Now I wonder, if it’s possible to place this Block Element anywhere on this site via shortcode, instead of the BLock-Elements-Settings > Element Type “Hook” > Hook name “after_main_content”?
Let’s say, I want to place it in the middle of a page-content between two container- or headline-blocks. How would I achieve this?
Thank you in advance and kind regards,
SaschaSeptember 9, 2022 at 1:22 am #2337740Fernando Customer Support
Hi Sascha,
It’s possible. You’ll need to create a portable hook. Example:
function your_shortcode($atts, $content = null) { ob_start(); do_action('hook_name'); return ob_get_clean(); } add_shortcode('portable_hook', 'your_shortcode');
Adding PHP: https://docs.generatepress.com/article/adding-php/#code-snippets
Now you can add
[portable_hook]
any where in your site, and then in your Element chooseCustom
as your hook and set it tohook_name
September 11, 2022 at 7:06 am #2339539Sascha
Brilliant, thank you so much! 🙏
By the way, is it possible to use this shortcode inside another Block-Element as well?
September 11, 2022 at 12:07 pm #2339872David
StaffCustomer SupportHi there,
it is possible to use it inside another element. Not sure if it will achieve what you expect but the hook will render.
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/ -
AuthorPosts
- You must be logged in to reply to this topic.