-
AuthorPosts
-
September 12, 2016 at 9:08 pm #685365
is it possible to get for each link in a mega menu the featured image in front of the link?
September 15, 2016 at 6:33 am #686728Hey 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,
IsmaelSeptember 16, 2016 at 6:39 pm #687678yes – see private content
- This reply was modified 8 years, 2 months ago by Guenni007.
September 20, 2016 at 5:05 am #688912Hi,
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,
IsmaelSeptember 20, 2016 at 3:12 pm #689309you rock !!!
the rest is css – Result see in private content so far on a test environment
- This reply was modified 8 years, 2 months ago by Guenni007.
September 22, 2016 at 5:20 am #690048May 4, 2023 at 10:42 am #1406426oha – 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.May 9, 2023 at 6:04 am #1406835Hi,
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,
IsmaelMay 9, 2023 at 9:12 am #1406846Thanks 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.May 12, 2023 at 6:19 pm #1407259Hi,
Guenni007 it sounds like you have this sorted out now, shall we close this then?Best regards,
MikeMay 25, 2023 at 3:42 pm #1408539 -
AuthorPosts
- The topic ‘on Mega Menu show in front of list points the featured image’ is closed to new replies.