Site logo

Archived topic

How to display a full post on a page?

7 replies · Started by Sascha on September 7, 2022

Viewing posts 1–8 of 8

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,
Sascha

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,
Sascha

You can try using a Block Element - Hook.

Then add a Dynamic Content Block in your Query Loop.

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,
Sascha

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 choose Customas your hook and set it to hook_name

Brilliant, thank you so much! 🙏

By the way, is it possible to use this shortcode inside another Block-Element as well?

Hi there,

it is possible to use it inside another element. Not sure if it will achieve what you expect but the hook will render.

This archived topic is closed to new replies.