Php WordPress菜单发布特色图片

Php WordPress菜单发布特色图片,php,jquery,html,css,wordpress,Php,Jquery,Html,Css,Wordpress,我有多个下拉菜单。 我想在菜单下拉菜单中的一篇或多篇文章的链接下方或旁边显示特色图像。可能吗? 我已将图像附加到此邮件。 我不想知道如何设计它或类似的东西。 假设我有“Siguranta”,我想在下面显示该帖子的特色图片,并在图片下面显示一个“阅读更多”链接。非常感谢 将过滤器添加到特定菜单中 add_filter('wp_nav_menu_args', 'add_filter_to_menus'); function add_filter_to_menus($args) { // Y

我有多个下拉菜单。 我想在菜单下拉菜单中的一篇或多篇文章的链接下方或旁边显示特色图像。可能吗? 我已将图像附加到此邮件。 我不想知道如何设计它或类似的东西。 假设我有“Siguranta”,我想在下面显示该帖子的特色图片,并在图片下面显示一个“阅读更多”链接。非常感谢


将过滤器添加到特定菜单中

add_filter('wp_nav_menu_args', 'add_filter_to_menus');
function add_filter_to_menus($args) {

    // You can test agasint things like $args['menu'], $args['menu_id'] or $args['theme_location']
    if( $args['theme_location'] == 'header_menu') {
        add_filter( 'wp_setup_nav_menu_item', 'filter_menu_items' );
    }
}
筛选菜单

function filter_menu_items($item)
{

    if ($item->type == 'taxonomy') {

        // For category menu items
        $cat_base = get_option('category_base');
        if (empty($cat_base)) {
            $cat_base = 'category';
        }

        // Get the path to the category (excluding the home and category base parts of the URL)
        $cat_path = str_replace(home_url() . '/' . $cat_base, '', $item->url);

        // Get category and image ID
        $cat      = get_category_by_path($cat_path, true);
        $thumb_id = get_term_meta($cat->term_id, '_term_image_id', true); // I'm using the 'Simple Term Meta' plugin to store an attachment ID as the featured image

    } else {
        // Get post and image ID
        $post_id  = url_to_postid($item->url);
        $thumb_id = get_post_thumbnail_id($post_id);
    }

    if (!empty($thumb_id)) {
        // Make the title just be the featured image.
        $item->title = wp_get_attachment_image($thumb_id, 'poster');
    }

    return $item;
}
然后,您希望删除在开始时应用的筛选器,以便处理的下一个菜单不会使用与上面在
filter\u menu\u items()
中定义的相同HTML

删除过滤器

 add_filter('wp_nav_menu_items','remove_filter_from_menus', 10, 2);
    function remove_filter_from_menus( $nav, $args ) {
        remove_filter( 'wp_setup_nav_menu_item', 'filter_menu_items' );
        return $nav;
    }

所以,我会回答我自己的问题。我终于用这段代码做到了:

//获取特色图像
$thumbnail=获取\u post\u缩略图($item->object\u id);
//显示特色图像
$item_output.=$thumbnail;

我必须提到,我在walker类中使用了这段代码。

那么,如何在菜单代码中实现这一点呢?谢谢。那对我一点帮助都没有。我想知道怎么做,我不想买。我有一个菜单,你喜欢吗?我不能说我不喜欢。谢谢你的帮助,但那不是我想要的。我只是想用我自己的菜单在我的WorpAddress菜单中添加帖子的特色图片。我已经在谷歌搜索中看到了这一点。我不想显示图标。我想显示特色图片。