首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在sprintf函数中可以使用get_the_post_thumbnail (Featured )吗?

在sprintf函数中可以使用get_the_post_thumbnail (Featured )吗?
EN

WordPress Development用户
提问于 2020-07-21 06:00:09
回答 1查看 124关注 0票数 0

我正在尝试添加我的超级菜单的帖子的特色形象。我想在div标签中显示特征图像。如何在sprintf函数中添加功能图像?

代码语言:javascript
复制
$thumbnail = '';
    if ( has_post_thumbnail( $item->object_id ) ) {
  $thumbnail = the_post_thumbnail_url( $item->object_id );
  }


class Walker_Nav_Primary extends Walker_Nav_menu {
    
    


    function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
        if ( array_search( 'menu-item-has-children', $item->classes )&& $depth==0 ) {
            $output .= sprintf( "\n%s\n", ( array_search( 'current-menu-item', $item->classes ) || array_search( 'current-page-parent', $item->classes ) ) ? '' : '', $item->url, $item->title );
        } 
        
        elseif ( array_search( 'menu-item-has-children', $item->classes )&& $depth==1 ) {
            $output .= sprintf( "\n%s\n", ( array_search( 'current-menu-item', $item->classes ) || array_search( 'current-page-parent', $item->classes ) ) ? '' : '', $item->url, $item->title );
        } 
        
        
        
        elseif ($depth==2){
            $output .= sprintf( "\n
            
             \\I want the featured image here
            
               %s\n", ( array_search( 'current-menu-item', $item->classes) ) ? '' : '', $item->url, $item->title );
        }
        
        
        
        
        else {
            $output .= sprintf( "\n%s\n", ( array_search( 'current-menu-item', $item->classes) ) ? '' : '', $item->url, $item->title );
        }
    }

    function start_lvl( &$output, $depth ) {
        $indent = str_repeat( "\t", $depth );
        if ($depth == 0) {
$output .= "\n$indent\n";
}


if ($depth == 1) {
$output .= "\n$indent\n";
}
        
        
        
  
    }
}
EN

回答 1

WordPress Development用户

回答已采纳

发布于 2020-07-21 06:18:50

我不确定我是否遗漏了您问题中更复杂的内容,但是sprintf不应该是img标记的问题。如果要将值指定为string,则可以使用%s处理程序。

代码语言:javascript
复制
sprintf('......', $thumbnail);
票数 0
EN
页面原文内容由WordPress Development提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://wordpress.stackexchange.com/questions/371446

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档