发表于:2010-04-20 | 没有回复
WordPress 模板包含了 index.php(主页模板)、archive.php(Archive/Category模板)、404.php(Not Found 错误页模板)、page.php(内容页(Page)模板)、single.php(内容页(Post)模板)等主要文件。在这些文件中又引用了sidebar.php(侧栏模板)、header.php(Header模板)、footer.php(Footer模板)。
很多博友为了在不同页面的侧边栏中显示不同的功能,在 sidebar.php 文件中利用 is_single() 等方法来判断当前页面的类型来改变显示的功能。这样做虽然没有问题,但过多的 php 操作会影响网页响影速度。查看 index.php 等文件,会发现引用 sidebar.php 文件的功能是用 WordPress 内置的 get_sidebar() 方法来完成的。该方法会在主题目录中查找 sidebar.php 文件,并将其包含进来。如果主题目录中没有 sidebar.php 文件,Wordpress 会将默认皮肤的 sidebar.php 文件包含进来(wp-content/themes/default/sidebar.php)。get_sidebar() 方法位于 wp-includes/general-template.php 文件中,内容如下: 阅读全文 »