Theme
WordPress主题修改
2010-07-23 18:10 # 今天突发奇想,觉得自己的主题也完善得差不多了,想试试提交到WordPress官网,结果一提交才知道自己的主题有多破陋。
纯CSS打造WordPress二级菜单导航栏
折腾了一个下午,终于用纯CSS实现了WordPress 下拉菜单导航栏,撒花!★,°:.☆( ̄▽ ̄)/$:.°★ 。 嗯,因为是为自己blog定制的,所以呢,目前只支持2层深度。
首頁添加文章縮圖功能
在 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分类目录列表的函数
修改主题的时候,需要显示分类目录列表,本来用的是
1<?php wp_list_categories(); ?> ,后来发现会始终显示“分类目录”四个字,十分之不美观,研究了一下,用
1<?php wp_list_cats('sort_column=name'); ?> 函数代替,解决了问题。o(* ̄▽ ̄*)o 推荐参考: https://www.renniaofei.com/tag/wordpress-tutorials/
footer的自动版权信息部分
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; }