2014-11-05 26 views
0

我想自定義以下代碼,以顯示當前頁面的所有同級頁面,但不是將它們輸出爲標題,而是將它們輸出爲bulletpoints(樣式化的bulletpoints,因此圖像,'images/bulletpoint.gif')。我有以下代碼顯示它們作爲名稱,但似乎無法將它們自定義爲顯示爲圖像。有任何想法嗎?PHP顯示同級頁面作爲設置圖像

非常感謝

<ul class="subnav_right"> 
<?php 
global $post; 
$current_page_parent = ($post->post_parent ? $post->post_parent : $post->ID); 

wp_list_pages(array(
    'title_li' => '', 
    'child_of' => $current_page_parent, 
    'depth' => '1') 
); 
?> 
</ul> 
+0

你上傳的圖像或全兄弟姐妹bulletpoints? – 2014-11-05 10:27:03

+0

只是希望每個兄弟姐妹被列爲子彈點圖像,沒有文字。因此,每個兄弟的一個圖像 – isabelle 2014-11-05 10:29:35

回答

1

您可以自定義使用walker.I已經使用學步車做到了。檢查下面的代碼:

行者等級:

class Custom_Walker extends Walker_Page { 

    function start_el(&$output, $page, $depth, $args, $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_post($current_page); 
      if (in_array($page->ID, $_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)); 
     $icon_class = get_post_meta($page->ID, 'icon_class', true); //Retrieve stored icon class from post meta 

     $output .= $indent . '<li class="' . $css_class . '">'; 
      $output .= '<a href="' . get_permalink($page->ID) . '">' . $link_before; 

       if($icon_class){ //Test if $icon_class exists 
        $output .= '<span class="' . $icon_class . '"></span>'; //If it exists output a span with the $icon_class attached to it 
       } 


      if($depth!=0){ 
       $output .= apply_filters('the_title', '', $page->ID); 
      }else { 
       $output .= apply_filters('the_title', $page->post_title, $page->ID); 
      } 
      $output .= $link_after . '</a>'; 

     if (!empty($show_date)) { 
      if ('modified' == $show_date) 
       $time = $page->post_modified; 
       else 
       $time = $page->post_date; 
       $output .= " " . mysql2date($date_format, $time); 
     } 
    } 
} 

通沃克在像argumnent:

wp_list_pages(array('title_li' => '', 
    'child_of' => $current_page_parent, 
    'depth' => '1', 
     'walker' => new Custom_Walker()) 
); 
+0

謝謝 - 仍然輸出頁面標題?而不是子彈點圖像?我在哪裏添加代碼以顯示圖像? – isabelle 2014-11-05 10:55:01

+0

yes在functions.php中。如果有幫助,請接受回答 – 2014-11-05 10:56:48

+0

現在工作嗎?添加類到functions.php? – 2014-11-05 11:18:30