Wordpress主题制作
个人主题的开发记录。主要介绍函数的使用。
创建主题
在wp-content下面的themes文件夹中创建自己主题的文件夹。我的文件夹名称是zingson。在文件下面创建style.css文件与index.php文件,一个主题中,这两个文件是必须的,其它的一些文件后面再加。 这两个文件建好之后,去后台就可以看到自己添加的主题,启用主题,打开首页能看到你index.php的内容了。
style.css文件说明
style.css文件中必须含有主题的注释头信息。 以下是默认主题的style.css文件:
/* Theme Name: Twenty Twelve Theme URI: http://wordpress.org/themes/twentytwelve Author: the WordPress team Author URI: http://wordpress.org/ Description: The 2012 theme for WordPress is a fully responsive theme that looks great on any device. Features include a front page template with its own widgets, an optional display font, styling for post formats on both index and single views, and an optional no-sidebar page template. Make it yours with a custom menu, header image, and background. Version: 1.3 License: GNU General Public License v2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html Tags: light, gray, white, one-column, two-columns, right-sidebar, flexible-width, custom-background, custom-header, custom-menu, editor-style, featured-images, flexible-header, full-width-template, microformats, post-formats, rtl-language-support, sticky-post, theme-options, translation-ready Text Domain: twentytwelve This theme, like WordPress, is licensed under the GPL. Use it to make something cool, have fun, and share what you've learned with others. */
上面内容是从默认主题复制过来的,大概可以看出什么意思了。 注释说明:
Theme Name: 这里填主题名称 Theme URI: 这里填主题介绍的网址,没有就填你的博客网址吧 Description: 这里填主题的简短介绍 Version: 版本号 Author: 作者名 Author URI: 作者的网址 Tags: 标签,多个用半角逗号隔开 Index.php
WordPress主题模板文件的列表。用户的主题中也可能带有其它样式表单、图片或文件,不过下面这些文件在WordPress中都有着特殊意义。
style.css:主样式表单。主题中必须包含style.css文件,而style.css文件中必须含有主题的注释头信息。
index.php:主模板。如果用户使用的主题有自己的模板,必须具备index.php文件。
Wordpress的实用函数
工具函数
bloginfo()
这个函数定义在wp-includes/general-template.php文件。 函数源代码: /** *Displayinformationabouttheblog. * *@seeget_bloginfo()Forpossiblevaluesfortheparameter. *@since0.71 * *@paramstring$showWhattodisplay. */ function bloginfo( $show='' ) { } echo get_bloginfo( $show, 'display' ); 看到这里使用的是get_bloginfo()两个参数,这里就不进一步追进了。 使用方法如下: 变量$show是要显示的参数,包括以下字段属性: name = 站点名称 description= 站点描述 admin_email = 管理员邮箱 url = 站点地址[use home_url('/') instead] wpurl = http://example/wp [use site_url('/') instead] stylesheet_directory = 主题样式文件夹 stylesheet_url = 主题样式路径 template_directory = 主题文件夹 template_url = 主题路径 atom_url = http://example/feed/atom rss2_url = http://example/feed rss_url = http://example/feed/rss pingback_url = http://example/wp/xmlrpc.php rdf_url = http://example/feed/rdf comments_atom_url = http://example/comments/feed/atom comments_rss2_url = http://example/comments/feed charset = UTF-8 html_type = text/html language = 语言 text_direction = ltr version = 版本 函数是把内容输出,表现在页面上,它的作用就像ehco; 如果想要赋值调用的话,我们需要使用Wordpress给我们提供的另一个函数get_bloginfo(), 例如:
网站优化: 如果已经有了固定的域名,有了成型的网站,设计的主题是私有主题(即设置之初就没有
打算共享),基于以上几个条件,bloginfo函数用处似乎不大。
使用实例:下面代码在index.php中。
get_bloginfo()
这个函数上面见过了。下面贴源代码出来:(代码看不下去可以看后面的解释) 这个函数定义在wp-includes/general-template.php 文件。 functionget_bloginfo( $show = '', $filter = 'raw' ) { switch( $show ) { case'home' : // DEPRECATED case'siteurl' : // DEPRECATED _deprecated_argument( __FUNCTION__, '2.2', sprintf( __('The %s
option is deprecated for the family of bloginfo()
functions.' ), $show ) . ' ' . sprintf( __( 'Use the %s
option instead.' ), 'url' ) ); case'url' : $output = home_url(); break; $output = site_url(); break; $output = get_option('blogdescription'); break; $output = get_feed_link('rdf'); break; $output = get_feed_link('rss'); break; $output = get_feed_link('rss2'); break; case'wpurl' : case'description': case'rdf_url': case'rss_url': case'rss2_url': case'atom_url':
相关推荐: