2012-11-13 3 views
1

다음은 메뉴의 축소판 그림을 끌어 당기는 Wordpress 기능입니다. 축소판이 없으면 "축소판 없음"을 표시하는 if/else를 어떻게 추가합니까?썸네일 디스플레이가없는 경우 "썸네일 없음"

이 나는 ​​시도했다 :

$item_output .= apply_filters('menu_item_thumbnail' , (!isset($args->thumbnail) && $args->thumbnail)) ? 'no thumbnail' : ''; 

그러나 이것은 아무런 영향을 미치지 않습니다. 죄송하지만이 질문이 벙어리지만 PHP는 모른다.

기능은 :

class Menu_With_Description extends Walker_Nav_Menu { 
    function start_el(&$output, $item, $depth, $args) { 
     global $wp_query; 


     // get user defined attributes for thumbnail images 
     $attr_defaults = array('class' => 'nav_thumb' , 'alt' => esc_attr($item->attr_title) , 'title' => esc_attr($item->attr_title)); 
     $attr = isset($args->thumbnail_attr) ? $args->thumbnail_attr : ''; 
     $attr = wp_parse_args($attr , $attr_defaults); 

     $item_output = $args->before; 

     // thumbnail image output 
     $item_output .= (isset($args->thumbnail_link) && $args->thumbnail_link) ? '<a' . $attributes . '>' : ''; 
     $item_output .= apply_filters('menu_item_thumbnail' , (isset($args->thumbnail) && $args->thumbnail) ? get_the_post_thumbnail($item->object_id , (isset($args->thumbnail_size)) ? $args->thumbnail_size : 'thumbnail' , $attr) : '' , $item , $args , $depth); 
     $item_output .= (isset($args->thumbnail_link) && $args->thumbnail_link) ? '</a>' : ''; 

     // menu link output 
     $item_output .= '<a'. $attributes .'>'; 
     $item_output .= $args->link_before . apply_filters('the_title', $item->title, $item->ID) . $args->link_after; 
     $item_output .= '</a>'; 

     // menu description output based on depth 
     $item_output .= ($args->desc_depth >= $depth) ? '<br /><span class="sub">' . $item->description . '</span>' : ''; 

     // close menu link anchor 
     $item_output .= $args->after; 

     $output .= apply_filters('walker_nav_menu_start_el', $item_output, $item, $depth, $args); 
    } 
} 

이 내 메뉴 위의 적용

add_filter('wp_nav_menu_args' , 'my_add_menu_descriptions'); 
function my_add_menu_descriptions($args) { 
    if ($args['theme_location'] == 'my_menu') { 
     $args['walker'] = new Menu_With_Description; 
     $args['desc_depth'] = 0; 
     $args['thumbnail'] = true; 
     $args['thumbnail_link'] = true; 
     $args['thumbnail_size'] = 'homeboxes'; 
     $args['thumbnail_attr'] = array('class' => 'nav_thumb my_thumb' , 'alt' => 'test' , 'title' => 'test'); 
     } 
    return $args; 
    } 
+0

는 워드 프레스있다 함수 has_post_thumbnail, 시도해 봤어? [Codex 페이지] (http://codex.wordpress.org/Function_Reference/has_post_thumbnail) – martinczerwi

+0

if/else를 포함하려면 어떻게 작성해야합니까? 나는 모든 '$ item_output. ='문장의 문법을 이해하지 못한다. – user1444027

답변

1

이 클래스를 수정하지 마십시오.

add_filter('menu_item_thumbnail', 'so_13368049_change_thumb', 10, 4); 

function so_13368049_change_thumb($thumb, $item , $args , $depth) 
{ 
    if('' == $thumb) 
     return 'No thumbnail'; 

    return $thumb; 
} 

을 그리고 당신은 클래스를 수정한다면, 그것은 다음과 같이해야한다 : 대신에이 필터를 사용
('NO THUMBNAIL' 대신 '')

$item_output .= apply_filters('menu_item_thumbnail' , (isset($args->thumbnail) && $args->thumbnail) ? get_the_post_thumbnail($item->object_id , (isset($args->thumbnail_size)) ? $args->thumbnail_size : 'thumbnail' , $attr) : 'NO THUMBNAIL' , $item , $args , $depth); 
+1

당신은 슈퍼 스타입니다! 감사!!! – user1444027