在本地测试这款名为Apple Theme的WordPress主题时,发现该主题将控制台调用在首页显示,也就是说,只要是以管理员身份登陆,就可以在博客首页快捷的进入WordPress的Dashboard控制项进行操作,这真的是一个非常聪明的想法,因为它可以解决WordPress后台运行慢的问题,大大的提高WordPress管理的效率。如图:

WordPress控制台调用在首页显示

然后我就琢磨着这个方法肯定也能在别的主题上实现?

首先将控制台需要用的图标拷贝到当前主题下,到Apple Theme发布页面下载Apple Theme,解压之后将adminbar文件夹复制到自己的themes/images/下

在当前主题CSS后面添加:

  1. /*Begin Admin Bar*/
  2.  
  3. .sbrbar {
  4. float: left;
  5. width: 50%;
  6. }
  7.  
  8. .sbrbar ul.admin-bar li {
  9. margin: 0 0 3px;
  10. }
  11. .sbrbar ul.admin-bar li a img {
  12. border: 0 solid;
  13. padding: 0 3px 0 0;
  14. vertical-align: middle;
  15. }

最后在Sidebar需要显示控制台的地方添加如下代码:

  1. <?php /* If this is the frontpage */ if ( is_home() ) { ?>
  2. <?php
  3. //  <!--begin Admin bar-->
  4. global $user_identity,$user_level;
  5. get_currentuserinfo();
  6. if ($user_identity) { ?>
  7. <li>
  8. <h3>Admin Dashboard</h3>
  9. <ul>
  10. <div class="sbrbar">
  11. <ul class="admin-bar">
  12. <li><a href="<?php echo get_option('siteurl'); ?>/wp-admin/" title="<?php _e('View the blog\'s summary','apple4us'); ?>"><img src="<?php bloginfo('template_url'); ?>/images/adminbar/icon_dashboard.png" alt="<?php _e('Dashboard','apple4us'); ?>" title="<?php _e('View the blog\'s summary','apple4us'); ?>" /><strong><?php _e('Admin','apple4us'); ?></strong></a></li>
  13. <?php if ($user_level >= 1) { ?>
  14. <?php // Get comments awaiting moderation
  15. $numcomments = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = '0'");
  16. ?>
  17. <li><a href="<?php echo get_option('siteurl'); ?>/wp-admin/post-new.php" title="<?php _e('Create a new post','apple4us'); ?>"><img src="<?php bloginfo('template_url'); ?>/images/adminbar/icon_post_new.png" alt="<?php _e('New Entry','apple4us'); ?>" title="<?php _e('Create a new post','apple4us'); ?>" /><?php _e('Post','apple4us'); ?></a></li>
  18. <li><a href="<?php echo get_option('siteurl'); ?>/wp-admin/page-new.php" title="<?php _e('Create a new page','apple4us'); ?>"><img src="<?php bloginfo('template_url'); ?>/images/adminbar/icon_page_new.png" alt="<?php _e('New Page','apple4us'); ?>" title="<?php _e('Create a new page','apple4us'); ?>" /><?php _e('Page','apple4us'); ?></a></li>
  19. <li><a href="<?php echo get_option('siteurl'); ?>/wp-admin/edit.php" title="<?php _e('Administer the entries','apple4us'); ?>"><img src="<?php bloginfo('template_url'); ?>/images/adminbar/icon_post_manage.png" alt="<?php _e('Manage Entries','apple4us'); ?>" title="<?php _e('Administer the entries','apple4us'); ?>" /><?php _e('Manage','apple4us'); ?></a></li>
  20. <li><a href="<?php echo get_option('siteurl'); ?>/wp-admin/link-manager.php" title="<?php _e('Administer the links','apple4us'); ?>"><img src="<?php bloginfo('template_url'); ?>/images/adminbar/icon_link_manage.png" alt="<?php _e('Links','apple4us'); ?>" title="<?php _e('Administer the links','apple4us'); ?>" /><?php _e('Links','apple4us'); ?></a></li>
  21. <li><a href="<?php echo get_option('siteurl'); ?>/wp-admin/upload.php" title="<?php _e('Administer the uploads','apple4us'); ?>"><img src="<?php bloginfo('template_url'); ?>/images/adminbar/icon_uploads_manage.png" alt="<?php _e('Uploads','apple4us'); ?>" title="<?php _e('Administer the uploads','apple4us'); ?>" /><?php _e('Uploads','apple4us'); ?></a></li>
  22. <?php } ?>
  23. </ul>
  24. </div>
  25. <?php if ($user_level >= 1) { ?>
  26. <div class="sbrbar">
  27. <ul class="admin-bar">
  28. <li><a href="<?php echo get_option('siteurl'); ?>/wp-admin/moderation.php" title="<?php _e('Administer the comments','apple4us'); ?>"><img src="<?php bloginfo('template_url'); ?>/images/adminbar/icon_comments.png" alt="<?php _e('Comments','apple4us'); ?>" title="<?php _e('Administer the comments','apple4us'); ?>" /><?php _e('Comment','apple4us'); ?> <?php if ( $numcomments ) : ?> (<strong><?php echo number_format($numcomments); ?></strong>)<?php endif; ?></a></li>
  29. <li><a href="<?php echo get_option('siteurl'); ?>/wp-admin/themes.php" title="<?php _e('Change the blog\'s look and feel','apple4us'); ?>"><img src="<?php bloginfo('template_url'); ?>/images/adminbar/icon_presentation.png" alt="<?php _e('Design','apple4us'); ?>" title="<?php _e('Change the blog\'s look and feel','apple4us'); ?>" /><?php _e('Design','apple4us'); ?></a></li>
  30. <li><a href="<?php echo get_option('siteurl'); ?>/wp-admin/plugins.php" title="<?php _e('Administer the plugins','apple4us'); ?>"><img src="<?php bloginfo('template_url'); ?>/images/adminbar/icon_plugins.png" alt="<?php _e('Plugins','apple4us'); ?>" title="<?php _e('Administer the plugins','apple4us'); ?>" /><?php _e('Plugins','apple4us'); ?></a></li>
  31. <li><a href="<?php echo get_option('siteurl'); ?>/wp-admin/options-general.php" title="<?php _e('Change the blog\'s options','apple4us'); ?>"><img src="<?php bloginfo('template_url'); ?>/images/adminbar/icon_options.png" alt="<?php _e('Options','apple4us'); ?>" title="<?php _e('Change the blog\'s options','apple4us'); ?>" /><?php _e('Options','apple4us'); ?></a></li>
  32. <li><a href="<?php echo get_option('siteurl'); ?>/wp-admin/profile.php" title="<?php _e('Administer the users','apple4us'); ?>"><img src="<?php bloginfo('template_url'); ?>/images/adminbar/icon_users.png" alt="<?php _e('Users','apple4us'); ?>" title="<?php _e('Administer the users','apple4us'); ?>" /><?php _e('Users','apple4us'); ?></a></li>
  33. <li><a href="<?php echo get_option('siteurl'); ?>/wp-login.php?action=logout" title="<?php _e('Log out of this account','apple4us'); ?>"><img src="<?php bloginfo('template_url'); ?>/images/adminbar/icon_logout.png" alt="<?php _e('Logout','apple4us'); ?>" title="<?php _e('Logout of Wordpress','apple4us'); ?>" /><?php _e('Logout &raquo;','apple4us'); ?></a></li>
  34. </ul>
  35. </div>
  36. </ul>
  37. </li>
  38. <?php } ?>
  39. <?php } ?>
  40. <?php } ?>

效果如图:

WordPress控制台在首页显示

最后要特别感谢Apple Theme的作者dupola

Comments are closed.