Are you a GenerateCustomer?

Do you have an active GP Premium or GenerateBlocks Pro license key?

Create a GenerateSupport account for GeneratePress and GenerateBlocks support in one dedicated place.

Create an account
Already have a GenerateSupport account? Login

Just browsing?

Feel free to browse the forums. Support for our free versions is provided on WordPress.org (GeneratePress, GenerateBlocks).

Want to become a premium user? Learn more below.

Off Canvas menu

  • Hello friends, I am using currently the Off Canvas Menu which contains nearly 800 blog posts. Please take a look here:

    https://www.kagels-trading.de/

    It becomes very difficult to add new posts or even more difficult to reorder this many blog posts in the off canvas menu. I have a very fast Macbook, but this doesn’t help much.

    I like the off canvas very much in order to present my content to my website visitors. But somehow it seems to me that there could exist a better possibility or plugin in order to handle my website content.

    Do you have a recommendation for me how to improve the off canvas menu?

    This would be very helpful.

    Thank you very much,

    Karsten

  • Hi Karsten,

    I recommend using GB query block to pull the posts from certain categories as your sub menus.

    In order to do so, I’ll take category Kursprognosen as an example, follow the steps:

    1. Go to appearance > menu, create a new menu, keep your current slide-out menu for now, and assign the new menu to slideout nev.

    2. In the new menu, only create the top level of menus, like Kursprognosen.

    3. add classes menu-item-has-children and gp_mega_menu to the top level menu item:
    https://app.screencast.com/nsR5MvS4KePLl

    4. Create a block element – hook, set hook name to custom hook > gp_mega_menu_categoryname, so in your case, the hook name would be gp_mega_menu_kursprognosen,

    5. Add a query block in the block element, you only need 1 text block to pull the title and post link, add Taxonomy parameter, select the categories, and choose kursprognosen.

    6. Add this PHP code to create the custom hook:

    add_filter( 'walker_nav_menu_start_el', 'db_sub_menu_item_hook', 10, 4 );
    
    function db_sub_menu_item_hook( $item_output, $item, $depth, $args ) {
    
        // Specify menu item class to target
        $class_string = 'gp_mega_item';
        $menu_item_classes = $item->classes;
    	
        if ( empty( $menu_item_classes ) || !in_array( $class_string , $menu_item_classes ) ) {
            return $item_output;
        }
        $menu_item_slug =  $item->post_name;
        // create custom hook from $class_string and $menu_item_slug
        // example result gp_mega_menu_{menu-item-name}
        $custom_hook_name = $class_string . '_' . $menu_item_slug;
        
        // Add our common and specific hooks
        ob_start(); 
        ?>
        <ul class="sub-menu custom-sub-menu">
         <?php do_action('gp_before_mega_item'); ?>
    	<?php do_action($custom_hook_name); ?>
    	<?php do_action('gp_after_mega_item'); ?>
        </ul>
        <?php
        $custom_sub_menu_html = ob_get_clean();
        // return the output after the menu items anchor
        $item_output .= $custom_sub_menu_html;
    
        return $item_output;
    }

    Adding PHP: https://docs.generatepress.com/article/adding-php/

    7. Repeat steps 2,3,4,5 for other categories.

    Let me know if this helps!

  • Thank you very much for your helpful support, dear Ying. I will try your solution.

  • You are welcome   🙂

    Hope it works out nicely!

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