所以我想在我的WordPress的網站上的導航菜單上工作。我試圖從hongkiat.com複製導航菜單(如圖所示)。您可以在Hongkiat的導航菜單中看到FIVE(5)父類別(設計/開發,技術,靈感,SOcial COmmerce和交易)。一旦用戶在父類別上懸停,它將在父類別下顯示最近的帖子。下拉導航菜單,顯示每個類別的最新帖子
無論如何,我設法編寫與父類別顯示的下拉菜單加上它的子類別。現在困境在於如何在用戶懸停的父類別下顯示最新的帖子(至少3個帖子)。
總之,這裏是我的代碼:
HTML/PHP
<ul>
<?php
global $post;
$myposts = get_posts('numberposts=3&offset=1');
foreach($myposts as $post) ;
$args = array(
'show_option_all' => '',
'hide_empty' => '0',
'orderby' => 'name',
'order' => 'ASC',
'style' => 'list',
'use_desc_for_title' => 1,
'child_of' => 0,
'hierarchical' => 1,
'title_li' => (''),
'show_option_none' => __(''),
'number' => null,
'echo' => 1,
'depth' => 2,
'current_category' => 0,
'pad_counts' => 0,
'taxonomy' => 'category',
'walker' => null
);
wp_list_categories($args);
?>
</ul>
CSS
.navone {
display:inline-block;
height:35px;
vertical-align:middle;
margin:0px auto;
font-family: "Raleway",san-serif;
font-feature-settings: normal;
font-kerning: auto;
font-language-override: normal;
font-size: 12px;
font-size-adjust: none;
font-stretch: normal;
font-style: normal;
font-synthesis: weight style;
font-variant: normal;
font-weight: 600 !important;
letter-spacing: 0.03em;
text-transform:uppercase;
}
.navone ul {
margin:0;
padding:0;
}
.navone ul ul {
display: none;
}
.navone ul li:hover > ul {
display: block;
-webkit-transition: all .25s ease;
-moz-transition: all .25s ease;
-ms-transition: all .25s ease;
-o-transition: all .25s ease;
transition: all .25s ease;
}
.navone ul {
list-style: none;
position: relative;
display: inline-table;
}
.navone ul:after {
content: ""; clear: both; display: block;
}
.navone ul li {
float: left;
cursor:pointer;
padding:10px 20px;
}
.navone ul li:hover {
background:#000;
}
.navone ul li:hover a {
color: #fff;
}
.navone ul li a {
display: block;
color: #FFF;
text-decoration: none;
}
.navone ul li ul {
width:200px;
z-index:9;
}
.navone ul ul {
background: #000;
padding: 0;
position: absolute;
top:100%;
left:0;
}
.navone ul ul li {
float: none;
position: relative;
padding:5px 10px;
}
.navone ul ul li a {
color: #fff;
}
.navone ul ul li a:hover {
-webkit-transition: all .25s ease;
-moz-transition: all .25s ease;
-ms-transition: all .25s ease;
-o-transition: all .25s ease;
transition: all .25s ease;
}
.navone ul ul ul {
position: absolute; left: 100%; top:0;
}
.navone ul li ul li {
padding:8px 10px;
-webkit-transition: all .25s ease;
-moz-transition: all .25s ease;
-ms-transition: all .25s ease;
-o-transition: all .25s ease;
transition: all .25s ease;
}
.navone ul li ul li:hover {
border-left:5px solid #F52100;
padding-left:20px;
-webkit-transition: all .25s ease;
-moz-transition: all .25s ease;
-ms-transition: all .25s ease;
-o-transition: all .25s ease;
transition: all .25s ease;
}
.navtwo {
display:inline;
}
如果有人湊ld幫助我或者指出我錯過了什麼,因爲我的代碼不起作用。我的代碼沒有錯誤,但我沒有達到我想要完成的目標。
任何人都可以伸出援助之手。
IMO,獲得了堅實的答案最好的地方,這將是[wordpress.se] (http://wordpress.stackexchange.com/),雖然你可能會得到一些精彩的答案在這裏毫無疑問,這是更專業的在那裏:P –
謝謝趙總,我只是認爲這是一個PHP相關的問題。人們可以幫忙。 –
我會做最簡單的方法是,首先:創建一個megamenu(擴展菜單),然後添加在我的菜單沃克的方式來增加側邊欄。然後,您可以註冊側邊欄並使用您希望的任何窗口部件(包括您自己的窗口部件)進行填充。我已經做了[菜單沃克要點](https://gist.github.com/dingo-d/73488da35e6a77e6cd1c),你可以看看,也許會有所幫助。 –