Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #685365

    is it possible to get for each link in a mega menu the featured image in front of the link?

    #686728

    Hey Guenter!

    Thank you for using Enfold.

    I’m sorry but I’m not sure what you meant by that. Could you please provide a screenshot of the mega menu layout that you want to create?

    Best regards,
    Ismael

    #687678

    yes – see private content

    • This reply was modified 8 years, 3 months ago by Guenni007.
    #688912

    Hi,

    Thank you for the info. Please try this in the functions.php file:

    add_filter('wp_nav_menu_objects', 'avf_wp_nav_menu_objects', 10, 2);
    function avf_wp_nav_menu_objects($sorted_menu_objects, $args) {
    
        // check menu name
        if ($args->menu->name != 'Main Menu') return $sorted_menu_objects;
    
        // edit the menu objects
        foreach ($sorted_menu_objects as $menu_object) {
            // searching for menu items linking to posts or pages
            // can add as many post types to the array
            if ( in_array($menu_object->object, array('post', 'page', 'portfolio', 'products')) ) {
                // set the title to the post_thumbnail if available
                // thumbnail size is the second parameter of get_the_post_thumbnail()
                $menu_object->title = has_post_thumbnail($menu_object->object_id) ? $menu_object->title . get_the_post_thumbnail($menu_object->object_id, 'thumbnail') : $menu_object->title;
            }
        }
    
        return $sorted_menu_objects;
    }

    Change the menu name from “Main Menu” to the name of your main menu set in the Appearance > Menus panel. It will return the menu title plus the featured image. It will require a few style adjustments.

    Best regards,
    Ismael

    #689309

    you rock !!!

    the rest is css – Result see in private content so far on a test environment

    • This reply was modified 8 years, 3 months ago by Guenni007.
    #690048

    Nice. Looks good. :)

    Cheers!
    Ismael

    #1406426

    oha – this is very old – but it so nice to have!

    But is there a method to limit the item selection here to mega menu items only?
    Above only the whole menu is selected, so if other second-level menu items have thumbnails, they will also get images. Of course I could hide this via css – but it would be nicer (more elegant) if the thumbnails would not be set there at all.

    #1406835

    Hi,

    To check if the $menu_object is a child of another menu item, you can use the menu_item_parent property. If the value of menu_item_parent is not equal to zero, then the menu item is a child of another menu item.

    if($menu_object->menu_item_parent != 0) {
       // do something
    }
    

    Best regards,
    Ismael

    #1406846

    Thanks that was the right hint:

    function avf_wp_nav_menu_objects($sorted_menu_objects, $args) {
        // check menu name
        if ($args->menu->name != 'menu-name') return $sorted_menu_objects;
        // edit the menu objects
        foreach ($sorted_menu_objects as $menu_object) {
            // searching for menu items linking to posts or pages
            // can add as many post types to the array
            if ( in_array($menu_object->object, array('post', 'page', 'portfolio', 'attachment')) ) {
                // set the title to the post_thumbnail if available
                // thumbnail size is the first parameter of get_the_post_thumbnail()
                $menu_object->title = (has_post_thumbnail($menu_object->object_id) && $menu_object->menu_item_parent != 0)  ? get_the_post_thumbnail($menu_object->object_id, 'thumbnail') . $menu_object->title : $menu_object->title;
            }
        }
        return $sorted_menu_objects;
    }
    add_filter('wp_nav_menu_objects', 'avf_wp_nav_menu_objects', 10, 2);


    but
    now I have decided to hide it only in the main menu, because in the hamburger menu, the little pictures at the top level items look good.

    #1407259

    Hi,
    Guenni007 it sounds like you have this sorted out now, shall we close this then?

    Best regards,
    Mike

    #1408539

    Yes

Viewing 11 posts - 1 through 11 (of 11 total)
  • The topic ‘on Mega Menu show in front of list points the featured image’ is closed to new replies.