簡體   English   中英

如何將自定義代碼添加到特定 <li> 構建導航時在wordpress中運行?

[英]How to add custom code to specific <li>s in wordpress while building navigation?

有問題的網站就在這里,我正在嘗試生成CSS下拉列表,但是wp_list_pages()沒有這樣的選項,使用外觀菜單中的WP菜單,我也無法獲得所需的效果(我曾經這種方法來生成我的頁腳鏈接)

這是理想的:

圖片

我知道如何生成菜單,但是我不知道如何在沒有黑客JavaScript解決方案的情況下在“汽車”菜單下獲取菜單。

理想的解決方案包括以模板名稱“ Car Showcase”為目標列表項,並讓我在其后生成PHP / HTML(進行下拉菜單所需的代碼)。 這對所有人有意義嗎?

為WordPress菜單創建自定義HTML的實際方法是創建Walker

http://codex.wordpress.org/Function_Reference/Walker_Class

您不僅可以創建另一個菜單並將其從以下位置拉出嗎?

wp_nav_menu( array( 'name' => 'menu-header'));

我在functions.php中擴展了walker類,它比應有的方式骯臟,我仍將目標定位為由ID生成的列表項,這是我不喜歡的解決方案,但這是我最干凈的解決方案可以提出,直到我找到更好的為止。

class Dropdowns extends Walker_page {   

function end_el(&$output, $item, $depth=0, $args=array()) {

    if ($item -> ID == 55) { //checks if the page id is the list item I want to make my dropdown under
         $vehicles = query_posts('post_type=vehicles'); //my custom post that I want to dropdown

         if ($vehicles) { //check for no entries
            //code for drop downs go here
         }

    }     
}  
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM