[Support request] Adding a full width section to a page with a sidebar

Home Forums Support [Support request] Adding a full width section to a page with a sidebar

Home Forums Support Adding a full width section to a page with a sidebar

Viewing 15 posts - 16 through 30 (of 33 total)
  • Author
    Posts
  • #1977908
    David
    Staff
    Customer Support

    Ok… if the shortcode method works then lets try this. Be prepared for some brain scrambling.

    1. First quick edit and change the status of the Hook Element that is outputting your shortcode to Draft. We may not need this… if this works.

    2. Add this PHP Snippet to your site:

    function db_hook_inside_shortcode($atts, $content = null) {
          ob_start();
          do_action('db_custom_comparison');
          return ob_get_clean();
    }
    add_shortcode('hooky_shortcode', 'db_hook_inside_shortcode');

    2. Now create your Block Element Page Hero for the Comparison table.
    Start with a GB Container Block to create the section, which you cans style for color, padding etc.
    Now add a shortcode block inside with this shortcode:

    [hooky_shortcode]

    3. Now add this PHP Snippet:

    add_action('db_custom_comparison', function(){
        $comparison = get_post_meta( get_the_id(), 'comparison_shortcode', true );
        if ( $comparison ) {
            echo do_shortcode( $comparison );
        }
    });

    So what it should do is output an empty hook inside your Block Element and the last function Hooks your custom field shortcode inside it.

    Test to see if that works, and then we can look at the other stuff.

    #1978074
    Stephen

    Thanks,

    I have gone through the steps and it looks like the comparison table is now showing above the content and in contained format.

    So it looks like the code/hook/snippet works. All i now would like to add is the option to add a H2 title above the comparison table.

    Again, thanks for your help.

    #1978111
    David
    Staff
    Customer Support

    Thats great !
    Ok so you can register a new custom field in your post. For example hero_title

    Now in the Block element add a GB Headline Block, and set its Dynamic Data to Post Meta and add your Custom Field name e.g hero_title in the field provided

    #1979913
    Stephen

    That worked like a charm! Thanks!

    One last question, sorry to keep going on.

    I would like to add a button button with a hyperlink under the comparison table. How would I achieve this?

    #1980124
    David
    Staff
    Customer Support

    Awesome !
    You can add a GB Buttons Block to your Block Element. The Label and the link both support dynamic data so you can use another custom field if you want.

    Or do you want it to Jump to a section on the page?

    #1980169
    Stephen

    Yes, the idea is to have it to jump to a section on the page.

    Would that need a different way of adding a button?

    #1980258
    David
    Staff
    Customer Support

    Jump links work like so:

    1. The element you want to jump to is given a unique HTML Anchor/ID eg. section – name it what you like but it should be unique for that page. In the Block editor you add the ID by selecting the Block ( you want to jump to ) in Advanced > HTML Anchor.

    2. The Button that will jump to the element is give an URL that matches that ID prefixed with a # eg. #section

    #1980316
    Stephen

    Thanks!

    And which PHP snippets do i need to add for the button title and button anchorlink?

    #1980757
    David
    Staff
    Customer Support

    No need for PHP – You can use a GenerateBlocks Buttons block in your Block Element:

    https://docs.generateblocks.com/article/buttons-overview/

    Make sure you use the GB one and not the core one as this will provide you with full styling controls in the editor.

    #1980781
    Stephen

    Got it,

    But how would I set a link / text on button per page?

    When i add the GB button I only seem to be able to add one link / text on button sitewide.

    #1980788
    David
    Staff
    Customer Support

    You can set them using the same Dynamic Data options and pull in another Custom Field for the title and the link.
    If its an on page link – i would assume the element you want to jump to would have the same ID ? You can use the same ID on every page.

    #1980824
    Stephen

    Yes, that makes sense, using the same element for the page jump.

    Where do i add the code for the dynamic data in the custom field? Do I set that in the elements/block section?

    #1980831
    David
    Staff
    Customer Support

    Click on the GB Button label where you would add the static text, and then in the Toolbar you will see the dynamic data option, select that, choose Post Meta, and add your Custom Field name in the field provided.

    #1982919
    Stephen

    Hi,

    I tried that, but it does not seem to work for some reason.

    I have added two screenshots in the private info with what I have done.

    Thanks

    #1982938
    David
    Staff
    Customer Support

    Aah.. there has to be something in the default URL field ( where it says ‘Paste URL or Type to Search’ ) – just add a #

Viewing 15 posts - 16 through 30 (of 33 total)
  • You must be logged in to reply to this topic.