2012-03-12 4 views
1

페이지에서 사용자 정의 필드 정보를 탐색 메뉴로 가져 오려고합니다. 전에 이런 문제가있었습니다 ... 저는 그냥 워커 메뉴를 "얻지"않고 작동 방법을 알려줍니다.탐색 메뉴의 Wordpress 사용자 정의 필드 정보?

기본적으로 페이지 제목 외에도 사용자 정의 필드에서 이미지 및 이미지 설명의 URL을 출력하고 일반 WP 페이지에 링크 된 메뉴 항목을 만들고 싶습니다. 순자산 메뉴-template.php 파일에서

, 내가 성공하지 이런 get_post_custom_keys()를 추가하여 start_el 기능을 수정 시도했다 :

$item_output .= '<a'. $attributes .'>'; 
$item_output .= get_post_custom_values("product_image", $item->ID); 
$item_output .= $args->link_before . apply_filters('the_title', $item->title, $item->ID) . $args->link_after; 

나는 또한 get_post_meta을 시도했습니다(); 제한된 성공을 거둔 사람도 있습니다. 내가 할 수 있었던 최선의 방법은 하드 정수 값을 지정하여 모든 링크에서 반복되는 이미지 중 하나를 얻는 것입니다. 또는 텍스트가 있지만 이미지가없는 올바른 게시물/페이지 값을 출력 할 수있었습니다.

누구나 해결책을 알고 있습니다. 내가 뭘 잘못하고있는 걸까요?

+0

누구나? 정말로 도움이 될지도 몰라. –

답변

0

nav 메뉴를 반복하여 동적으로 렌더링하는 것이 더 쉬울 것입니다. 아래의 코드는 functions.php 파일에 등록되어있는 nav 메뉴 위치에 지정된 주어진 nav 메뉴를 반복하도록합니다 :

<ul id="some-menu-id" class="my-fancy-menu"> 
<?php 
    $menu_name = 'primary'; 
    if (($locations = get_nav_menu_locations()) && isset($locations[ $menu_name ])) { 
     $menu = wp_get_nav_menu_object($locations[ $menu_name ]); 
     $menu_items = wp_get_nav_menu_items($menu->term_id); 
     foreach ((array) $menu_items as $key => $menu_item) { 
      // at this point you can get the custom meta from the page 
      $image = get_post_meta($menu_item->object_id, '_custom_field_image_url', true); 
      $image_description = get_post_meta($menu_item->object_id, '_custom_field_image_description', true); 
      // here we are getting the title and URL to the page 
      $title = $menu_item->title; 
      $url = $menu_item->url; 
      $slug = basename($menu_item->url); 
      // this allows us to add a current class 
      if (basename($_SERVER['REQUEST_URI']) == $slug) { $current = ' current-menu-item'; } else { $current = ''; } 
      $menu_list .= '<li class="page-id-'.$menu_item->object_id.$current.'"><a href="' . $url . '">' . $title . '</a><br /><p>'.$image_description.'<br />'.$image.'</p></li>'; 
     } 
    } 
    echo $menu_list; 
?> 
</ul> 
관련 문제