2013-02-09 2 views
0

특정 메뉴가있는 모든 페이지를 나열하고 "고급 사용자 정의 필드"로 생성 된 제목 및 사용자 정의 필드 이미지를로드하는 메뉴가있는 사이트에서 작업하고 있습니다. 제목을 표시하려고하지만 이미지를 표시하려고하면 모든 메뉴 링크의 현재 페이지에서 사용자 정의 필드 이미지가 표시됩니다.사용자 정의 필드가있는 Wordpress 목록 페이지

예 : "http://appelhat.dk/bordplader/"예 : 마우스가 페이지의 buttom을 터치하면 메뉴가 위로 이동합니다.

여기에 아마도 get_field보다는 get_post_meta를 사용하려고 코드를

<nav id="main-navigation"> 
     <ul> 
      <?php 
       $template = 'gallery.php'; 
       $Pages = $wpdb->get_col("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wp_page_template' AND meta_value = '$template'"); 
       foreach($Pages as $Page) { 
        $exclude_Pages .= $Page . ','; 
       } 
       $pages = get_pages("include=$exclude_Pages"); 

      foreach ($pages as $page): 

       $title = $page->post_title 
       ?> 
       <li> 
        <a href="<?php echo get_page_link($page->ID); ?>"> 
         <span class="title"><?php echo $title ?></span> 
        <?php 
         $attachment_id = get_field('front_billede'); 
         $size = "thumbnail"; 
         $image = wp_get_attachment_image_src($attachment_id, $size); 
        ?> 
        <img src="<?php echo $image[0]; ?>" /> 
        </a> 
       </li> 
      <?php endforeach; ?> 
     </ul> 
    </nav> 

감사

답변

1

입니다. get_field가 원하는 $ page-> ID가 아닌 global $ post-> ID를 호출하는 것처럼 들립니다. 태그가 해당 ID를 사용하는 모든 보장하기 위해 WP_Query 또는 get_posts를 사용하여 -

$attachment_id = get_post_meta($page->ID, 'front_billede', true);

다른 방법으로는 보조 루프를 만들 수 있습니다.

+0

감사 :이 같은 페이지 메뉴에서 사용할 다음

class WP_Image_Walker extends Walker_Page { function start_lvl(&$output, $depth = 0, $args = array()) { $indent = str_repeat("\t", $depth); $output .= "\n$indent<ul class='children list-inline'>\n"; } function start_el(&$output, $page, $depth = 0, $args = array(), $current_page = 0) { if ($depth) { $indent = str_repeat("\t", $depth); } else { $indent = ''; } extract($args, EXTR_SKIP); $css_class = array('page_item', 'page-item-'.$page->ID); if (!empty($current_page)) { $_current_page = get_page($current_page); _get_post_ancestors($_current_page); if (isset($_current_page->ancestors) && in_array($page->ID, (array) $_current_page->ancestors)) $css_class[] = 'current_page_ancestor'; if ($page->ID == $current_page) $css_class[] = 'current_page_item'; elseif ($_current_page && $page->ID == $_current_page->post_parent) $css_class[] = 'current_page_parent'; } elseif ($page->ID == get_option('page_for_posts')) { $css_class[] = 'current_page_parent'; } $css_class = implode(' ', apply_filters('page_css_class', $css_class, $page, $depth, $args, $current_page)); $image = get_field('image_field', $page->ID); $output .= $indent . '<li class="' . $css_class . '">' . '<a href="' . get_permalink($page->ID) . '">'; $output .= '<img src="' . $image['url'] . '" alt="' . apply_filters('the_title', $page->post_title, $page->ID) . '" />' . '</a>'; if (!empty($show_date)) { if ('modified' == $show_date) $time = $page->post_modified; else $time = $page->post_date; $output .= " " . mysql2date($date_format, $time); } } } 

: 여기에 내가 이전에 사용했던 예이다 – MyRevenge

0

에서이 상대적으로 오래된 질문 알지만,이 맥락에서 get_field 사용하려는 경우 다음 당신은 단순히 오버로드 방법을 사용할 수 있습니다 :이 같은 사용자 정의 메뉴를 만들려면, 또한

$attachment_id = get_field('front_billede', $page->ID); 

을 Wordpress에서는 사용자 정의 Walker를 추천합니다. 그것은 완벽하게 작동

<?php wp_page_menu(array('walker' => new WP_Image_Walker(), 'container' => 'false', 'menu_class' => 'nav-home')); ?> 
관련 문제