2016-09-08 3 views
0

wp_list_pages에서 맞춤 보행기를 사용하고 있습니다. 이제 자녀가있는 경우 $ link 및 $ checkchildren의 값을 변경하려고합니다.wp_list_pages 어린이가 없는지 확인하십시오.

나는이 아이

$children = wp_list_pages(array(
    'sort_column' => 'menu_order', 
    'title_li' => '', 
    'echo'  => 1, 
    'walker' => new Sidebar_Custom_Walker() 
)); 




class Sidebar_Custom_Walker extends Walker_Page { 
    function start_el(&$output, $page, $depth, $args, $current_page = 0) { 
     $output .= $indent . '<li class="rtChild">'; 
     $linkcss ="c1"; // should be blank if no children 
     $output .= '<a href="' . get_permalink($page->ID) . '" class="'.$linkcss .'">' . $link_before; 
     $output .= apply_filters('the_title', $page->post_title, $page->ID); 
     $output .= $link_after . '</a> 
     $checkchildren = '<span class="plusBtn"></span>'; // should be blank if no children 
     $output .= $checkchildren; 
    } 
} 

답변

0

이 방법 start_el 내부의 워드 프레스 내장 함수 get_pages()을 사용하는 것입니다 할 수있는 빠른 방법이없는 경우 $ linkcss 및 $ checkchildren가 null가되고 싶어요. 의이 헤어지고 보자

첫 번째 부분 :

<?php 

    class Sidebar_Custom_Walker extends Walker_Page { 

     function start_el(&$output, $page, $depth, $args, $current_page = 0) { 

      $output    .= $indent . '<li class="rtChild">'; 

새로운 부분 :

  // Retrieve page children with get_pages() 
      // in combination with current $page->ID. 
      $page_children  = get_pages(array('child_of' => $page->ID)); 

      // Count amount of pages 
      $page_children_count = count($page_children); 

      // Does this page have children? 
      if($page_children_count > 0){ 
       // Page has children 
       $linkcss   = "c1"; 
       $checkchildren = '<span class="plusBtn"></span>'; 
      }else{ 
       // Page has no children 
       $linkcss   = null; 
       $checkchildren = null; 
      } 

그리고 우리의 출력은 동일하게 유지 :

  $output .= '<a href="' . get_permalink($page->ID) . '" class="'.$linkcss .'">' . $link_before; 
      $output .= apply_filters('the_title', $page->post_title, $page->ID); 
      $output .= $link_after . '</a>'; 
      $output .= $checkchildren; 

     } 

    } 


?> 

나는 아니에요 문자열을 무효화 한 다음 ano 내부에서 문자열을 사용하는 것이 좋습니다. the 변수는 나중에 $output입니다.

개인적으로 나는 비워을 설정합니다 :

$linkcss  = ""; 
$checkchildren = ""; 
관련 문제