前言
最近又写了个网站,也是基于wordpress,LEE周刊官网:www.leeweekly.com。这个网站和轩枫阁的部分功能有所不同,部分功能困扰了挺久,通过Google搜索到了各种解决方案,记录成文备忘。
LEE周刊新版PC官网设计开发总结:http://t.cn/RyzrUD4
functions.php
下面根据需求,对各种能实现进行简单介绍。
先对functions.php文件进行介绍,通过代码实现各功能。
1. widgets sidebar 侧边栏小工具
- wordpress二次开发技巧-functions.php篇

/** widgets sidebar 侧边栏小工具*/
if( function_exists('register_sidebar'<span class="crayon-sy">) ) {
register_sidebar(array(
'name' <span class="crayon-o">=> 'First_sidebar'<span class="crayon-sy">,
'before_widget' <span class="crayon-o">=> ''<span class="crayon-sy">,
'after_widget' <span class="crayon-o">=> ''<span class="crayon-sy">,
'before_title' <span class="crayon-o">=> '<h4>'<span class="crayon-sy">,
'after_title' <span class="crayon-o">=> '</h4>'
));
register_sidebar(array(
'name' <span class="crayon-o">=> 'Second_sidebar'<span class="crayon-sy">,
'before_widget' <span class="crayon-o">=> ''<span class="crayon-sy">,
'after_widget' <span class="crayon-o">=> ''<span class="crayon-sy">,
'before_title' <span class="crayon-o">=> '<h4>'<span class="crayon-sy">,
'after_title' <span class="crayon-o">=> '</h4>'
));
register_sidebar(array(
'name' <span class="crayon-o">=> 'Third_sidebar'<span class="crayon-sy">,
'before_widget' <span class="crayon-o">=> ''<span class="crayon-sy">,
'after_widget' <span class="crayon-o">=> ''<span class="crayon-sy">,
'before_title' <span class="crayon-o">=> '<h4>'<span class="crayon-sy">,
'after_title' <span class="crayon-o">=> '</h4>'
));
register_sidebar(array(
'name' <span class="crayon-o">=> 'Fourth_sidebar'<span class="crayon-sy">,
'before_widget' <span class="crayon-o">=> ''<span class="crayon-sy">,
'after_widget' <span class="crayon-o">=> ''<span class="crayon-sy">,
'before_title' <span class="crayon-o">=> '<h4>'<span class="crayon-sy">,
'after_title' <span class="crayon-o">=> '</h4>'
));
}
register_nav_menus(array("primary" => "Primary Navigation"));
2. 后台支持自定义菜单
- wordpress二次开发技巧-functions.php篇

/*nav 后台自定义菜单*/
if(function_exists('register_nav_menus'<span class="crayon-sy">)){
register_nav_menus(
array(
'header-menu' <span class="crayon-o">=> __( '导航自定义菜单' <span class="crayon-sy">),
'footer-menu' <span class="crayon-o">=> __( '页角自定义菜单' <span class="crayon-sy">),
'sider-menu' <span class="crayon-o">=> __('侧边栏菜单'<span class="crayon-sy">),
'primary' <span class="crayon-o">=> __( 'Primary Navigation'<span class="crayon-sy">, 'lee' <span class="crayon-sy">),
)
);
}
输出菜单,在如header.php插入显示菜单的代码
<?php wp_nav_menu( array( 'container' <span class="crayon-o">=> '' <span class="crayon-sy">) ); ?>
3. 面包屑导航
// 面包屑导航注册代码
function wheatv_breadcrumbs() {
$delimiter = '<i>></i>'<span class="crayon-sy">;
$name = '首页'<span class="crayon-sy">; //text for the 'Home' link
$currentBefore = ''<span class="crayon-sy">;
$currentAfter = ''<span class="crayon-sy">;
if ( !is_home() && !is_front_page() || is_paged() ) {
echo ''<span class="crayon-sy">;
global $post;
// $home = get_bloginfo('url');
$home = get_option('home'<span class="crayon-sy">);
echo '<a href="'<span class="crayon-sy">.$home.'" >'<span class="crayon-sy">. $name . ' </a>' <span class="crayon-sy">. $delimiter . ' '<span class="crayon-sy">;
if ( is_category() ) {
global $wp_query;
$cat_obj = $wp_query->get_queried_object();
$thisCat = $cat_obj->term_id;
$thisCat = get_category($thisCat);
$parentCat = get_category($thisCat->parent);
if ($thisCat->parent != 0) echo(get_category_parents($parentCat, TRUE, ' ' <span class="crayon-sy">. $delimiter . ' '<span class="crayon-sy">));
echo $currentBefore . ''<span class="crayon-sy">;
single_cat_title();
echo '' <span class=&