[Support request] How to display a full post on a page?

Home Forums Support [Support request] How to display a full post on a page?

Home Forums Support How to display a full post on a page?

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #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,
    Sascha

    #2336475
    Fernando
    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.

    #2336545
    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

    #2336548
    Fernando
    Customer Support

    You can try using a Block Element – Hook.

    Then add a Dynamic Content Block in your Query Loop.

    #2337728
    Sascha

    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

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

    #2339539
    Sascha

    Brilliant, thank you so much! 🙏

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

    #2339872
    David
    Staff
    Customer Support

    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.

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.