主题修改指南

自己制作一个WordPress主题或许难度很大,找个心仪的模板修改是我们菜鸟的不二选择,但是如果你不懂那些代码是很难完成的,所以我为大家搜集了一些模板常见的文件名、命令、函数,希望对你们有所帮助...

WordPress基本模板文件

一套完整的WordPress模板应至少具有如下文件:

style.css : CSS(样式表)文件

index.php : 主页模板

archive.php : Archive/Category模板

404.php : Not Found 错误页模板

comments.php : 留言/回复模板

footer.php : Footer模板

header.php : Header模板

sidebar.php : 侧栏模板

page.php : 内容页(Page)模板

single.php : 内容页(Post)模板

searchform.php : 搜索表单模板

search.php : 搜索结果模板

当然,具体到特定的某款模板,可能不止这些文件,但一般而言,这些文件是每套模板所必备的。

基本条件判断Tag

is_home() : 是否为主页

is_single() : 是否为内容页(Post)

is_page() : 是否为内容页(Page)

is_category() : 是否为Category/Archive页

is_tag() : 是否为Tag存档页

is_date() : 是否为指定日期存档页

is_year() : 是否为指定年份存档页

is_month() : 是否为指定月份存档页

is_day() : 是否为指定日存档页

is_time() : 是否为指定时间存档页

is_archive() : 是否为存档页

is_search() : 是否为搜索结果页

is_404() : 是否为 “HTTP 404: Not Found” 错误页

is_paged() : 主页/Category/Archive页是否以多页显示

Header部分常用到的PHP函数

<span class="pun"><?</span><span class="pln">php bloginfo</span><span class="pun">(’</span><span class="pln">name</span><span class="pun">’);</span> <span class="pun">?></span> : 博客名称(Title)

<span class="pun"><?</span><span class="pln">php bloginfo</span><span class="pun">(’</span><span class="pln">stylesheet_url</span><span class="pun">’);</span> <span class="pun">?></span> : CSS文件路径

<span class="pun"><?</span><span class="pln">php bloginfo</span><span class="pun">(’</span><span class="pln">pingback_url</span><span class="pun">’);</span> <span class="pun">?></span> : PingBack Url

<span class="pun"><?</span><span class="pln">php bloginfo</span><span class="pun">(’</span><span class="pln">template_url</span><span class="pun">’);</span> <span class="pun">?></span> : 模板文件路径

<span class="pun"><?</span><span class="pln">php bloginfo</span><span class="pun">(’</span><span class="pln">version</span><span class="pun">’);</span> <span class="pun">?></span> : WordPress版本

<span class="pun"><?</span><span class="pln">php bloginfo</span><span class="pun">(’</span><span class="pln">atom_url</span><span class="pun">’);</span> <span class="pun">?></span> : Atom Url

<span class="pun"><?</span><span class="pln">php bloginfo</span><span class="pun">(’</span><span class="pln">rss2_url</span><span class="pun">’);</span> <span class="pun">?></span> : RSS 2.o Url

<span class="pun"><?</span><span class="pln">php bloginfo</span><span class="pun">(’</span><span class="pln">url</span><span class="pun">’);</span> <span class="pun">?></span> : 博客 Url

<span class="pun"><?</span><span class="pln">php bloginfo</span><span class="pun">(’</span><span class="pln">html_type</span><span class="pun">’);</span> <span class="pun">?></span> : 博客网页Html类型

<span class="pun"><?</span><span class="pln">php bloginfo</span><span class="pun">(’</span><span class="pln">charset</span><span class="pun">’);</span> <span class="pun">?></span> : 博客网页编码

<span class="pun"><?</span><span class="pln">php bloginfo</span><span class="pun">(’</span><span class="pln">description</span><span class="pun">’);</span> <span class="pun">?></span> : 博客描述

<span class="pun"><?</span><span class="pln">php wp_title</span><span class="pun">();</span> <span class="pun">?></span> : 特定内容页(Post/Page)的标题

模板常用的PHP函数及命令

<span class="pun"><?</span><span class="pln">php get_header</span><span class="pun">();</span> <span class="pun">?></span> : 调用Header模板

<span class="pun"><?</span><span class="pln">php get_sidebar</span><span class="pun">();</span> <span class="pun">?></span> : 调用Sidebar模板

<span class="pun"><?</span><span class="pln">php get_footer</span><span class="pun">();</span> <span class="pun">?></span> : 调用Footer模板

<span class="pun"><?</span><span class="pln">php the_content</span><span class="pun">();</span> <span class="pun">?></span> : 显示内容(Post/Page)

<span class="pun"><?</span><span class="pln">php </span><span class="kwd">if</span><span class="pun">(</span><span class="pln">have_posts</span><span class="pun">())</span> <span class="pun">:</span> <span class="pun">?></span> : 检查是否存在Post/Page

<span class="pun"><?</span><span class="pln">php </span><span class="kwd">while</span><span class="pun">(</span><span class="pln">have_posts</span><span class="pun">())</span> <span class="pun">:</span><span class="pln"> the_post</span><span class="pun">();</span> <span class="pun">?></span> : 如果存在Post/Page则予以显示

<span class="pun"><?</span><span class="pln">php endwhile</span><span class="pun">;</span> <span class="pun">?></span> : While 结束

<span class="pun"><?</span><span class="pln">php endif</span><span class="pun">;</span> <span class="pun">?></span> : If 结束

<span class="pun"><?</span><span class="pln">php the_time</span><span class="pun">(’字符串’)</span> <span class="pun">?></span> : 显示时间,时间格式由“字符串”参数决定

<span class="pun"><?</span><span class="pln">php comments_popup_link</span><span class="pun">();</span> <span class="pun">?></span> : 正文中的留言链接。

如果使用 comments_popup_script() ,则留言会在新窗口中打开,反之,则在当前窗口打开

<span class="pun"><?</span><span class="pln">php the_title</span><span class="pun">();</span> <span class="pun">?></span> : 内容页(Post/Page)标题

<span class="pun"><?</span><span class="pln">php the_permalink</span><span class="pun">()</span> <span class="pun">?></span> : 内容页(Post/Page) Url

<span class="pun"><?</span><span class="pln">php the_category</span><span class="pun">(’,</span> <span class="pun">‘)</span> <span class="pun">?></span> : 特定内容页(Post/Page)所属Category

<span class="pun"><?</span><span class="pln">php the_author</span><span class="pun">();</span> <span class="pun">?></span> : 作者

<span class="pun"><?</span><span class="pln">php the_ID</span><span class="pun">();</span> <span class="pun">?></span> : 特定内容页(Post/Page) ID

<span class="pun"><?</span><span class="pln">php edit_post_link</span><span class="pun">();</span> <span class="pun">?></span> : 如果用户已登录并具有权限,显示编辑链接

<span class="pun"><?</span><span class="pln">php get_links_list</span><span class="pun">();</span> <span class="pun">?></span> : 显示Blogroll中的链接

<span class="pun"><?</span><span class="pln">php comments_template</span><span class="pun">();</span> <span class="pun">?></span> : 调用留言/回复模板

<span class="pun"><?</span><span class="pln">php wp_list_pages</span><span class="pun">();</span> <span class="pun">?></span> : 显示Page列表

<span class="pun"><?</span><span class="pln">php wp_list_categories</span><span class="pun">();</span> <span class="pun">?></span> : 显示Categories列表

<span class="pun"><?</span><span class="pln">php next_post_link</span><span class="pun">(’</span> <span class="pun">%</span><span class="pln">link </span><span class="pun">‘);</span> <span class="pun">?></span> : 下一篇文章链接

<span class="pun"><?</span><span class="pln">php previous_post_link</span><span class="pun">(’%</span><span class="pln">link</span><span class="pun">’);</span> <span class="pun">?></span> : 上一篇文章链接

<span class="pun"><?</span><span class="pln">php get_calendar</span><span class="pun">();</span> <span class="pun">?></span> : 日历

<span class="pun"><?</span><span class="pln">php wp_get_archives</span><span class="pun">()</span> <span class="pun">?></span> : 显示内容存档

<span class="pun"><?</span><span class="pln">php posts_nav_link</span><span class="pun">();</span> <span class="pun">?></span> : 导航,显示上一篇/下一篇文章链接

<span class="pun"><?</span><span class="pln">php include</span><span class="pun">(</span><span class="pln">TEMPLATEPATH </span><span class="pun">.</span> <span class="pun">‘/文件名’);</span> <span class="pun">?></span> : 嵌入其他文件,可为定制的模板或其他类型文件

与模板相关的其他函数

<span class="pun"><?</span><span class="pln">php _e</span><span class="pun">(’</span><span class="typ">Message</span><span class="pun">’);</span> <span class="pun">?></span> : 输出相应信息

<span class="pun"><?</span><span class="pln">php wp_register</span><span class="pun">();</span> <span class="pun">?></span> : 显示注册链接

<span class="pun"><?</span><span class="pln">php wp_loginout</span><span class="pun">();</span> <span class="pun">?></span> : 显示登录/注销链接

<span class="pln"><!–next page–></span> : 将当前内容分页

<span class="pln"><!–more–></span> : 将当前内容截断,以不在主页/目录页显示全部内容

<span class="pun"><?</span><span class="pln">php timer_stop</span><span class="pun">(</span><span class="lit">1</span><span class="pun">);</span> <span class="pun">?></span> : 网页加载时间(秒)

<span class="pun"><?</span><span class="pln">php echo get_num_queries</span><span class="pun">();</span> <span class="pun">?></span> : 网页加载查询量

# 本文来自主题笔记!


共有 2 条评论

  1. 开头的图片吓我一跳。哈哈。。。。博主调皮。。

    1. LIFET说道:

      @天津网站建设 哈哈 没有呢 随便找的图 尺寸不配

发表评论

电子邮件地址不会被公开。 必填项已用*标注