WordPress橫式下拉選單
WordPress的佈景,絕大多數都是以直式選單為主,像文章分類、鏈結、彙整等等,雖然也有橫式選單的外掛(DL MENU或是AmR Tab Menu Navigation),但使用不便(難以自訂項目),也不甚美觀…
今天偶然在WordPress Themes Free中看到一個佈景主題jillij-100,很是符合我想要的效果,可按這裡下載。
要移殖到其它佈景(以佈景A代稱),有四個檔案要瀏覽:
/jillij-100/header.php
將下述代碼貼至佈景A的<head></head>間
<!--[if lt IE 7]> <style type="text/css" media="screen, tv, projection"> body { behavior: url("<?php bloginfo('stylesheet_directory'); ?>/code/csshover.htc"); } </style> <![endif]-->
/jillij-100/sidebar.php
用以產生橫式選單的php碼,複製內容並貼至佈景A要顯示的地方
/jillij-100/code/csshover.htc
都不用改,直接複製code目錄到佈景A的目錄即可
/jillij-100/style.css
設定下拉選單的呈現方式,複製下述代碼至佈景A的style.css,可自行變更修改樣式
/* Rolling Menu Styles */ #sidebar { display: block; border: 0px; padding: 0px 0px 0px 0px; margin: 0px 0px 0px 20px; z-index: 5; position: relative; } #sidebar ul { width:100%; min-height: 30px; list-style-type: none; padding: 0px 0px 0px 0px; margin: 0px 0px 0px 0px; z-index: 500; font-weight: bold; font-size: 1.2em; font-family: 'Trebuchet MS', 'Lucida Grande', Verdana, Arial, Sans-Serif; } #sidebar li { display: inline; float: left; min-height: 20px; position: relative; text-align: left; padding: 5px 16px 5px; margin: 0px 0px 0px 0px; } #sidebar h2 { padding: 0px; margin: 0px; font-size: 1em; } #sidebar li ul { width: 150px; height: auto; top: 100%; left: 0px; font-weight: normal; font-size: 1em; } #sidebar li.LargeMenu ul { width: 200px; height: auto; top: 100%; left: 0px; } #sidebar li ul li { text-align: left; width: 118px; height: auto; min-height: auto; display: block; } #sidebar li.LargeMenu ul li { text-align: left; width: 198px; height: auto; min-height: auto; display: block; } #sidebar a { text-decoration: none; } #sidebar li li ul { top: 0; left: 0; } #sidebar li li:hover ul { left: 150px; } /* initialy hide all sub sidebars */ #sidebar ul ul, #sidebar ul li:hover ul ul, #sidebar ul ul li:hover ul ul, #sidebar ul ul ul li:hover ul ul, #sidebar ul ul ul ul li:hover ul ul { position: absolute; display:none; } /* display them on hover */ #sidebar li:hover ul, #sidebar ul li:hover ul, #sidebar ul ul li:hover ul, #sidebar ul ul ul li:hover ul, #sidebar ul ul ul ul li:hover ul, #sidebar ul ul ul ul ul li:hover ul { display: block; } #sidebar #PhpWebcontent { display:none; } /* define the consecutive colors */ #sidebar { color: #FFFFFF; } #sidebar ul{ background: #940709; -moz-opacity:0.88; /* for mozilla */ opacity: 0.88; /* for safari */ khtml-opacity: 0.88 /* for konquerer and older safari */ } #sidebar ul ul { background: #940709; } #sidebar ul li { background: #940709; } #feeds li { background: url(images/feed.png) top left no-repeat; padding-left: 18px; } #sidebar h2 { color: #FFFFFF; } #sidebar a { color: #FFFFFF; } #sidebar ul li:hover { background: #333333; } #sidebar ul li ul { } #sidebar ul li ul li { background: #333333; } #sidebar ul li ul li:hover { background: #666666; } #sidebar ul li ul ul li{ background: #666666; } #sidebar ul li ul ul li:hover { background: #999999; } #wp-calendar { empty-cells: show; margin: 10px auto 0; width: 155px; } #wp-calendar #next a { padding-right: 10px; text-align: right; } #wp-calendar #prev a { padding-left: 10px; text-align: left; } #wp-calendar a { display: block; background: #000000; } #wp-calendar caption { text-align: center; width: 100%; } #wp-calendar td { padding: 3px 0; text-align: center; }
注意:style.css和sidebar.php的id sidebar名稱,可能會和原有的佈景相衝突,記得要修改它的名稱