博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
WordPress常用的函数、方法,判断是否是首页、文章页等函数
阅读量:4048 次
发布时间:2019-05-25

本文共 3972 字,大约阅读时间需要 13 分钟。

WordPress常用的函数、方法,判断是否是首页、文章页等函数

选择使用 WordPress来搭建博客,主要原因便在于WordPress有较高的流行度,还有各种围绕其进行的开发的扩展功能应有尽有,基本上可以说我们在博客建设中所需的任何功能,都已有人想到并得到实现,让你不必在博客具体的技术实现及功能扩展方面投入过多的精力,而更专注于内容建设。

本文以技术手册的方式简单汇总 WordPress主题模板的基本资料,希望能对 WordPress 主题模板开发的朋友解渴。

WordPress 主题模板基本文件

一套完整的 WordPress 主题模板应至少具有如下文件:,WordPress基本模板文件,WordPress模板必备文件:

01  style.css : CSS(样式表)文件02  index.php : 主页模板03  archive.php : Archive/Category模板04  404.php : Not Found 错误页模板05  comments.php : 留言/回复模板06  footer.php : Footer模板07  header.php : Header模板08  sidebar.php : 侧栏模板09  page.php : 内容页(Page)模板10  single.php : 内容页(Post)模板11  searchform.php : 搜索表单模板12  search.php : 搜索结果模板

基本条件判断Tag

01  is_home() : 是否为主页02  is_single() : 是否为内容页(Post)03  is_page() : 是否为内容页(Page)04  is_category() : 是否为Category/Archive页05  is_tag() : 是否为Tag存档页06  s_date() : 是否为指定日期存档页07  is_year() : 是否为指定年份存档页08  is_month() : 是否为指定月份存档页09  is_day() : 是否为指定日存档页10  is_time() : 是否为指定时间存档页11  is_archive() : 是否为存档页12  is_search() : 是否为搜索结果页13  s_404() : 是否为 “HTTP 404: Not Found” 错误页14  is_paged() : 主页/Category/Archive页是否以多页显示

Header部分常用到的PHP 函数

01  
: 博客名称(Title)02
: CSS文件路径03
: PingBack Url04
: 模板文件路径05
: WordPress版本06
: Atom Url07
: RSS 2.o Url08
: 博客 Url09
: 博客网页Html类型10
: 博客网页编码11
: 博客描述12
: 特定内容页(Post/Page)的标题

模板常用的PHP 函数及命令

01  
: 调用Header模板02
: 调用Sidebar模板03
: 调用Footer模板04
: 显示内容(Post/Page)05
: 显示摘要06
: 检查是否存在Post/Page07
: 如果存在Post/Page则予以显示08
: While 结束09
: If 结束10
: 显示时间,时间格式由“字符串”参数决定,具体参考PHP手册11
: 正文中的留言链接。如果使用 comments_popup_script() ,则留言会在新窗口中打开,反之,则在当前窗口打开12
: 内容页(Post/Page)标题13
: 内容页(Post/Page) Url14
: 特定内容页(Post/Page)所属Category15
: 作者16
: 特定内容页(Post/Page) ID17
: 如果用户已登录并具有权限,显示编辑链接18
: 显示Blogroll中的链接19
: 调用留言/回复模板20
: 显示Page列表21
: 显示Categories列表22
: 下一篇文章链接23
: 上一篇文章链接24
: 日历25
: 显示内容存档26
: 导航,显示上一篇/下一篇文章链接27
: 嵌入其他文件,可为定制的模板或其他类型文件

与模板相关的其他 函数

1   
: 输出相应信息2
: 显示注册链接3
: 显示登录/注销链接4
: 将当前内容分页5
: 将当前内容截断,以不在主页/目录页显示全部内容6
: 网页加载时间(秒)7
: 网页加载查询量

其它

1   
调用最近的10篇日志2
6
  • ”>7
  • 8

    随机调用10篇日志

    1   
    ’); ?> 调用标签2 3

    标签存在时调用

    1   
    调用标签云2
    获得4篇12分类中的日志

    再来一些更详细的判断函数

    1   
    2 3 //这里写你想显示的内容,包括函数4 5

    下面是直接来自wordpress.org

    01  is_single() 判断是否是具体文章的页面02  is_single(’17′) 判断是否是具体文章(id=17)的页面03  is_single(’Beef Stew’) 判断是否是具体文章(标题判断)的页面04  is_single(’beef-stew’) 判断是否是具体文章(slug判断)的页面05  comments_open() 是否留言开启06  pings_open() 是否开启ping07  is_page() 是否是页面08  is_page(’42′) 同single,id判断,即是否是id为42的页面09  is_page(’About Me’) title判断10  is_page(’about-me’) slug判断11  is_category() 是否是分类12  is_category(’6′) 同single,id判断,即是否是id为6的分类13  is_category(’Cheeses’) title判断14  is_category(’cheeses’) slug判断15  in_category(’5′) 判断当前的文章是否属于分类516  is_author() 将所有的作者的页面显示出来17  is_author(’1337′) 显示author number为1337的页面18  is_author(’Elite Hacker’) 通过昵称来显示当前作者的页面19  is_author(’elite-hacker’)20  is_date()21  is_year()22  is_month()23  is_day()24  is_time()25  is_archive() 判断当前是否是归档页面26  is_search() 判断是否是搜索27  is_404() 判断页面是否40428  is_paged() 判断是否翻页,比如你当前的blog是http://domain.com29  显示http: //domain.com?paged=2的时候,这个判断将返回真,通过这个函数可以配合is_home来控制某些只能在首页显示的界30  面,例如: if (is_home() && !is_paged() )31  is_attachment() //When an attachment document to a post or Page is being displayed. An attachment is an image or other file uploaded through the post editor’s upload utility. Attachments can be displayed on their own ‘page’ or template. For more information, see Using Image and File Attachments.32  is_feed() //When the site requested is a Syndication.This tag is not typically used by users; it is used internally by33  WordPress and is available for Plugin Developers.34  is_trackback() //When the site requested is WordPress’ hook into its Trackback engine. This tag is not typically used by users; it is used internally by WordPress and is available for Plugin Developers.

    转载地址:http://mfuci.baihongyu.com/

    你可能感兴趣的文章
    android 代码实现圆角
    查看>>
    flutter-解析json
    查看>>
    android中shader的使用
    查看>>
    java LinkedList与ArrayList迭代器遍历和for遍历对比
    查看>>
    drat中构造方法
    查看>>
    JavaScript的一些基础-数据类型
    查看>>
    JavaScript基础知识(2)
    查看>>
    转载一个webview开车指南以及实际项目中的使用
    查看>>
    android中对于非属性动画的整理
    查看>>
    一个简单的TabLayout的使用
    查看>>
    ReactNative使用Redux例子
    查看>>
    Promise的基本使用
    查看>>
    coursesa课程 Python 3 programming 统计文件有多少单词
    查看>>
    coursesa课程 Python 3 programming 输出每一行句子的第三个单词
    查看>>
    Returning a value from a function
    查看>>
    coursesa课程 Python 3 programming Functions can call other functions 函数调用另一个函数
    查看>>
    coursesa课程 Python 3 programming The while Statement
    查看>>
    course_2_assessment_6
    查看>>
    coursesa课程 Python 3 programming course_2_assessment_7 多参数函数练习题
    查看>>
    coursesa课程 Python 3 programming course_2_assessment_8 sorted练习题
    查看>>