快轉到主要內容

纯CSS打造WordPress二级菜单导航栏

·212 字·1 分鐘
Y Cheung
作者
Y Cheung
Blogger, Programer & Traveler.

折腾了一个下午,终于用纯CSS实现了WordPress 下拉菜单导航栏,撒花!★,°:.☆( ̄▽ ̄)/$:.°★ 。 嗯,因为是为自己blog定制的,所以呢,目前只支持2层深度。

分享一下我的代码啦~ 嗯,重点是display的运用。 PHP代码:

1<?php wp_list_pages('sort_column=menu_order&depth=2&title_li=&exclude=' . $options['exclude_pages']); ?>

CSS样式代码:

1#navigation {height:38px;background:#666666;} .menu li{ float:left; text-transform:capitalize; padding:8px 10px; background:#666666; -moz-border-radius-bottomright: 5px; -webkit-border-bottom-right-radius: 5px; -moz-border-radius-bottomleft: 5px; -webkit-border-bottom-left-radius: 5px; } .menu li a{padding:8px 10px;color:#ccc;font-family:微软雅黑;font-size:15px;} .menu li a:hover{border-bottom:2px solid #339999;color:#eb4640;font-weight:bold;} .menu li ul{display:none;} .menu li:hover ul{display:block;}

相關文章

技巧笔记

·78 字·1 分鐘
能直接寫 html 的, 就不要用 php. 能直接寫中文的, 就不要用翻譯. 能直接表達的, 就不要有太多嵌套. 修改 css 不要一味添加, 有時刪除會更好. 影響網頁速度最嚴重的是 javascript 或 jQuery 裏的 DOM.

首頁添加文章縮圖功能

·113 字·1 分鐘
在 functions.php 中開啟WordPress的自帶縮圖功能。 1<?php 2 3// 支援 WordPress 2.9 的自帶縮圖功能 4 5if ( function_exists( 'add_theme_support' ) ) { add_theme_support( 'post-thumbnails' ); } ?> 在 index.php 中的the_content 之前添加以下代碼 1<?php if ( has_post_thumbnail() ) : ?> [<?php the_post_thumbnail( array( 150, 150 ), array( 'class' => 'alignleft' ) ); ?>](<?php the_permalink(); ?>) <?php endif; ?> 自帶縮圖功能目前不支持外鏈圖片。

获取WordPress分类目录列表的函数

·90 字·1 分鐘
修改主题的时候,需要显示分类目录列表,本来用的是 1<?php wp_list_categories(); ?> ,后来发现会始终显示“分类目录”四个字,十分之不美观,研究了一下,用 1<?php wp_list_cats('sort_column=name'); ?> 函数代替,解决了问题。o(* ̄▽ ̄*)o 推荐参考: https://www.renniaofei.com/tag/wordpress-tutorials/

footer的自动版权信息部分

·124 字·1 分鐘
PHP代码: 1<?php global $wpdb; 2$post_datetimes = $wpdb->get_row($wpdb->prepare("SELECT YEAR(min(post_date_gmt)) AS firstyear, YEAR(max(post_date_gmt)) AS lastyear FROM $wpdb->posts WHERE post_date_gmt > 1970")); 3 4if ($post_datetimes) { 5 $firstpost_year = $post_datetimes->firstyear; 6 $lastpost_year = $post_datetimes->lastyear; 7 $copyright = $firstpost_year; 8 if($firstpost_year != $lastpost_year) { 9 $copyright .= '-'. $lastpost_year; 10 } 11 $copyright .= ' '; 12 echo $copyright; 13 } ?> 14 < ?php bloginfo('name'); ?><?php echo get_option('home'); ?> / Theme designed by 你的大名 CSS代码: 1 #copyright { float:left; display:inline; margin:55px 0 0 -10px; color:#777; } #copyright li { float:left; display:inline; font-size:11px; margin:0 10px 0 0; padding:0 0 0 13px; background:url(img/footer_line.gif) no-repeat left center; } #copyright li a, #copyright li a:visited { text-decoration:underline; }

添加jQuery lazy load plugin插件

·133 字·1 分鐘
有时候写日志会添加很多很大的图片,且这些图片所在图床由于我国特殊国情常常loading得非常慢。 为了提高访客的愉悦体验,特添加了这个插件,用来延迟加载图片。