WordPress主题模板层次和常用模板函数
WordPress 是目前世界上使用最广泛的博客系统,是一款开源的PHP软件。因为使用者众多,所以WordPress社区非常活跃,有丰富的插件模板资源。使用WordPress可以快速搭建独立的博客网站。很多知名科技博客也是WordPress搭建的,例如:雷锋网、钛媒体等。下面PHP站为WordPress主题开发者整理了一下制作WordPress主题的必备知识。
WordPress主题模板层次
首页:
- home.php
- index.php
文章页:
- single-{post_type}.php – 如果文章类型是videos(即视频),WordPress就会去查找single-videos.php(WordPress 3.0及以上版本支持)
- single.php
- index.php
页面:
- 自定义模板 – 在WordPress后台创建页面的地方,右侧边栏可以选择页面的自定义模板
- page-{slug}.php – 如果页面的缩略名是news,WordPress将会查找 page-news.php(WordPress 2.9及以上版本支持)
- page-{id}.php – 如果页面ID是6,WordPress将会查找page-6.php
- page.php
- index.php
分类:
- category-{slug}.php – 如果分类的缩略名为news,WordPress将会查找category-news.php(WordPress 2.9及以上版本支持)
- category-{id}.php -如果分类ID为6,WordPress将会查找category-6.php
- category.php
- archive.php
- index.php
标签
- tag-{slug}.php – 如果标签缩略名为sometag,WordPress将会查找tag-sometag.php
- tag-{id}.php – 如果标签ID为6,WordPress将会查找tag-6.php(WordPress 2.9及以上版本支持)
- tag.php
- archive.php
- index.php
作者:
- author-{nicename}.php – 如果作者的昵称为rami,WordPress将会查找author-rami.php(WordPress 3.0及以上版本支持)
- author-{id}.php – 如果作者ID为6,WordPress将会查找author-6.php(WordPress 3.0及以上版本支持)
- author.php
- archive.php
- index.php
日期页面:
- date.php
- archive.php
- index.php
搜索结果:
- search.php
- index.php
404 (未找到)页面
- 404.php
- index.php
附件页面:
- MIME_type.php – 可以是任何MIME类型 (image.php, video.php, audio.php, application.php 或者其他).
- attachment.php
- single.php
- index.php
WordPress主题 – 判断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页是否以多页显示
判断Tag在WordPress主题里常用于侧边栏(sidebar.php)模板文件
WordPress主题 – Header 常用PHP函数
: 博客名称(Title)
: CSS文件路径
: PingBack Url
: 模板文件路径
: WordPress版本
: Atom Url
: RSS 2.o Url
: 博客 Url
: 博客网页Html类型
: 博客网页编码
: 博客描述
: 特定内容页(Post/Page)的标题
WordPress主题 – 模板常用的PHP函数
: 调用Header模板
: 调用Sidebar模板
: 调用Footer模板
: 显示内容(Post/Page)
: 检查是否存在Post/Page
: 如果存在Post/Page则予以显示
: While 结束
: If 结束
: 显示时间,时间格式由“字符串”参数决定,具体参考PHP手册
: 正文中的留言链接。如果使用 comments_popup_script() ,则留言会在新窗口中打开,反之,则在当前窗口打开
: 内容页(Post/Page)标题
: 内容页(Post/Page) Url
: 特定内容页(Post/Page)所属Category
: 作者
: 特定内容页(Post/Page) ID
: 如果用户已登录并具有权限,显示编辑链接
: 显示Blogroll中的链接
: 调用留言/回复模板
: 显示Page列表
: 显示Categories列表
: 下一篇文章链接
: 上一篇文章链接
: 日历
: 显示内容存档
: 导航,显示上一篇/下一篇文章链接
: 嵌入其他文件,可为定制的模板或其他类型文件
WordPress主题 – 与模板相关的其他函数
: 输出相应信息
: 显示注册链接
: 显示登录/注销链接
: 将当前内容分页
: 将当前内容截断,以不在主页/目录页显示全部内容
: 网页加载时间(秒)
: 网页加载查询量
转载请注明出处:http://www.php-z.com/753.html

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

If you are an experienced PHP developer, you might have the feeling that you’ve been there and done that already.You have developed a significant number of applications, debugged millions of lines of code, and tweaked a bunch of scripts to achieve op

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

Wordpress site file access is restricted: troubleshooting the reason why .txt file cannot be accessed recently. Some users encountered a problem when configuring the mini program business domain name: �...
