2016-02-23 40 views
0

我有一個在下面我的WordPress網站生成工具欄菜單中的一些代碼...添加Bootstrap類/風格WordPress的wp_list_pages菜單項

<ul> 
    <?php 
    if($post->post_parent) 
     $children = wp_list_pages("title_li=&sort_column=menu_order&child_of=".$post->post_parent."&echo=1"); 
    else 
     $children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=1"); 
     if ($children) { ?> 
      <?php echo $children; ?> 
     </div> 
    <?php } ?> 
</ul> 

這以下列方式輸出代碼...

<ul> 
    <li class="page_item page-item-94 current_page_item"><a href="#">Menu Item</a></li> 
</ul> 

的問題是,我需要用我的引導3的風格和輸出列表如下...

<div class="list-group submenu"> 
    <a href="#" class="list-group-item">Menu Item</a> 
</div> 

基本上我需要將list-group-item的類添加到輸出列表項中的a標籤。這是否可能?

+0

看看這個答案呃 http://wordpress.stackexchange.com/questions/130877/ways-to-give-a-wp-list-pages-menu-link-specific-class-names –

+0

你需要一個「沃克」這個(來定製類) –

回答

1

您可以通過jQuery的做到這一點

$(document).ready(function(){ 
    $("ul").find("li").each(function(){ 
     $(this).addClass("YourClass"); 
    }) 
}) 
0

您可以將您的沃克類簡單地延長wp_list_pages輸出修改$output把課functions.php

class NS_CS_Walker extends Walker_page { 
    function start_el(&$output, $page, $depth, $args, $current_page) { 
     if ($depth) { 
      $indent = str_repeat("\t", $depth); 
     } else { 
      $indent = ''; 
     } 

     extract($args, EXTR_SKIP); 
     $output .= $indent . '<li><div>' . get_post_meta($post_id, $key, $single) . '</div></li>'; 
     // modify your output here 

    } // End start_el 
} // End Walker Class 

然後你的渲染代碼應該是

$args = array(
    'walker'  => new NS_CS_Walker() 
     // your extra $args would be here 
); 

wp_list_pages($args); 
+0

你好。我無法獲取已添加的渲染代碼。這是基於我的上述例子還是我做錯了什麼? – lowercase

+0

@lowercase添加有問題的更改 – Noman

+0

更改的問題,希望更有意義 – lowercase