WordPress常用函数
- 格式:doc
- 大小:65.50 KB
- 文档页数:16
WordPress代码插⼊⽂章函数:wp_insert_post【描述】该函数可在数据库中插⼊⽂章(及页⾯)。
它可以进⾏处理变量,检查操作,填充⽇期/时间等缺失变量等⼯作。
该函数以对象作为变量,返回已创建⽂章的编号(出错时返回0)。
【使⽤⽅法】<?php wp_insert_post( $post, $wp_error ); ?>【参数】$post(array) (必需) ⼀个⽂章对象. 与数据库wp_posts表中的字段⼀⼀对应默认: ⽆重要: 如果设置$post[‘ID’]的值,将不会创建这个ID的⽂章. 设置这个值将会更新这个ID的⽂章. 简单的说,创建⼀个⽂章 $post[‘ID’] 必须为空或不设置这个值.$post = array('ID' => [ <post id> ] //需要更新的⽂章编号'menu_order' => [ <order> ] //如果新⽂章是页⾯,设置显⽰顺序'comment_status' => [ 'closed' | 'open' ] // 评论的状态,'closed'关闭评论.'ping_status' => [ 'closed' | 'open' ] // ping的状态,'closed' 关闭 pingbacks和trackbacks'pinged' => [ ? ] //该⽂章被ping到的地址'post_author' => [ <user ID> ] //作者编号'post_category' => [ array(<category id>, <...>) ] //⽂章归类数组'post_content' => [ <the text of the post> ] //⽂章内容,必填'post_date' => [ Y-m-d H:i:s ] //⽂章编辑⽇期'post_date_gmt' => [ Y-m-d H:i:s ] //⽂章编辑GMT⽇期'post_excerpt' => [ <an excerpt> ] //摘要信息'post_name' => [ <the name> ] // (slug) ⽂章别名'post_parent' => [ <post ID> ] //新⽂章的⽗⽂章编号'post_password' => [ ? ] //⽂章浏览密码'post_status' => [ 'draft' | 'publish' | 'pending'| 'future' | 'private' ] //新⽂章的状态'post_title' => [ <the title> ] //⽂章标题,必填'post_type' => [ 'post' | 'page' | 'link' | 'nav_menu_item' | custom post type ] //⽂章类型:⽂章、页⾯、链接、菜单、其他定制类型'tags_input' => [ '<tag>, <tag>, <...>' ] //标签字符串'to_ping' => [ ? ] //该⽂章需要ping到的地址'tax_input' => [ array( 'taxonomy_name' => array( 'term', 'term2', 'term3' ) ) ] // 附加注释数组);$wp_error(布尔型) (可选) 失败时是否返回WP_Error对象默认: false【返回的值】若⽂章成功加⼊数据库,返回⽂章编号。
WordPress开发中⽤于标题显⽰的相关函数使⽤解析single_cat_title()函数single_cat_title()函数,⽇常中我们很少会⽤到,但这个函数会给我们解决很多问题,诸如当前页⾯的⽬录、标签,该函数不依附于 WordPress 主循环中,也不能放⼊主循环中使⽤。
描述获取当前页⾯的分类、标签。
<?php single_cat_title($prefix,$display); ?>$prefix :⽤于设置在标题之前显⽰的内容。
$display :⽤于设置是直接显⽰还是返回到变量。
实例在此摘取 WordPress 2011 默认主题中,category.php ⽂件第18⾏左右位置的代码<?phpprintf( __( 'Category Archives: %s', 'twentyeleven' ), '<span>' . single_cat_title( '', false ) . '</span>' );>get_the_title 和 the_titleget_the_title 和 the_title 两个函数⽤来在⽂章页⾯显⽰⽂章标题的函数,之所以将两个函数合并到⼀篇⽂章⾥⾯去是因为这两个函是⼀个实现,只不过 the_title 默认直接显⽰,get_the_title 默认返回字符串,如果你对此⼼存疑惑,那请你往下看。
函数详解get_the_title 和 the_title这两个函数主要⽤于在循环中显⽰当前⽂章的标题,请注意 the_title 这个函数必须使⽤在循环中。
两者的区别在于,get_the_title仅能以字符串形式返回⽂章标题,⽽ the_title 可以设置标题前后的⾃定义字符,以及是显⽰还是返回字符串。
the_title 函数使⽤、参数详解<?php the_title( $before, $after, $echo ); ?>$before标题前的字符$after标题后的字符$echo显⽰、还是返回字符串,默认为truethe_title⽰例<?php the_title( ‘=>', ‘<=' ); ?>以本⽂为例,我们将得到以下这样的标题:‘=>get_the_title 和 the_title<='get_the_title 函数使⽤、参数详解<?php $myTitle = get_the_title($ID); ?>以上代码我们将得到⽂章标题的变量$myTitle;$ID ⽤于设置⽂章 ID ,当然在循环中我们可以省略此参数。
wordpress的tag函数使用教程
wordpress的tag函数有三个:wp_get_post_tags函数、single_cat_title函数和single_tag_title函数。
wp_get_post_tags函数可以根据某个文章页面或者某篇文章的ID来获取该文章的tag,获取的结果被放置到一个tag数组中。
例如:
if (is_single())
{
$keywords =” “;
$tags = wp_get_post_tags($post->ID);
foreach ($tags as $tag ) {$keywords = $keywords . $tag->name . “,”;
}
echo $keywords;
}
首先判断是否是单文章页面,根据当前文章的ID($post->ID)来获取当前文章的tag,然后取得其name($tag->name),并将其组合输出。
single_cat_title函数可以用来获取WordPress文章分类页面的title。
例如:
<?php
$str = single_cat_title();
echo $str;
>
single_tag_title函数则可以获取tag页面的title。
例如:
<?php
$str = single_tag_title();
echo $str;
>
值得注意的是:single_cat_title()可以用来在tag页面上获取当前页面的title;但是single_tag_title()却不能获取Wordpress分类页面的title。
WordPress分类目录调用函数wp展开全文把分类目录列表显示在博客首页,有利于提高用户体验。
WordPress 经常用到的博客分类目录调用函数是wp_list_cats,对于该函数,普通博主可能只会简单地应用,其实通过给它设置不同的参数,可以显示不同的分类目录列表的效果。
下面博客吧介绍介绍下WP 分类目录调用函数wp_list_cats的参数使用。
WordPress分类目录调用函数例子:<?phpwp_list_cats("sort_column=ID&hide_empty=0&optioncount=1") ;?>该函数表示:分类目录按ID排列,不显示没有文章的分类,显示分类目录下的文章数量wp_list_cats函数参数如下:•sort_column•默认值为ID,可选ID 或name,分别表示按ID 值或分类名称排序•sort_order•默认值为asc,可选asc 或 desc,分别表示排序递增或递减•list•默认值为1,可选 0 或 1,设定是否按序显示,将会在分类上加上<ul> <li>标签•optiondates•默认值为0,可选 0 或 1,设定是否显示每个分类下最新发表文章的发表日期•optioncount•默认值为0,可选 0 或 1,设定是否显示分类下的文章数•hide_empty•默认值为1,可选 0 或 1,设定是否隐藏无文章的分类目录•use_desc_for_title•默认值为1,可选 0 或 1,设定分类链接的title是否显示为分类说明,如<a title=”分类说明” href=”…>•children•默认值为1,可选 0 或 1,设定是否显示子分类•hierarchical•默认值为1,可选 0 或 1,设定子分类是否以层级方式显示•child_of•无默认值,设定只显示某项分类(ID)的子分类,child_of=分类ID值,有设定此项目的话,hide_empty要设为0•exclude•无默认值,设定不要显示的分类ID,可设置多个分类,如exclude=ID1,ID2,ID3,…..•feed•无默认值,设定分类RSS 的显示文字,如feed=RSS,如果这个项目有设定的话,分类之後将会显示分类Feed的链接•feed_image•无默认值,设定分类 RSS 的图片路径,如 feed=images/rss.gif,如果同时有设定 feed_image 与 feed,则将以 feed_image 为主提醒:通常0是表示‘否定’,1是表示‘肯定’。
1.根据分类来制定导航条2.删除控制面板首页多余的板块3.显示所有最新的文章4.发表文章时对文章进行修改的操作一套完整的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 : 搜索结果模板当然,具体到特定的某款模板,可能不止这些文件,但一般而言,这些文件是每套模板所必备的。
基本条件判断Tagis_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 Foun d” 错误页is_paged() : 主页/Category/Archive页是否以多页显示Header部分常用到的PHP函数<?php blog info(‟name‟); ?> : 博客名称(Title)<?php bloginfo(‟stylesheet_url‟); ?> : CSS文件路径<?php bloginfo(‟pingback_url‟); ?> : PingBack Url<?php bloginfo(‟template_url‟); ?> : 模板文件路径<?php bloginfo(‟version‟); ?> : WordPress版本<?php bloginfo(‟atom_url‟); ?> : Atom Url<?php bloginfo(‟rss2_url‟); ?> : RSS 2.o Url<?php bloginfo(‟url‟); ?> : 博客Url<?php bloginfo(‟html_type‟); ?> : 博客网页Html类型<?php bloginfo(‟charset‟); ?> : 博客网页编码<?php bloginfo(‟description‟); ?> : 博客描述<?php wp_title(); ?> : 特定内容页(Post/Page)的标题模板常用的PHP函数及命令<?php get_header(); ?> : 调用Header模板<?php get_sidebar(); ?> : 调用Sidebar模板<?php get_footer(); ?> : 调用Footer模板<?php the_content(); ?> : 显示内容(Post/Page)<?php if(have_posts()) : ?> : 检查是否存在Post/Page<?php while(have_posts()) : the_post(); ?> : 如果存在Post/Page则予以显示<?php endwhile; ?> : While 结束<?php endif; ?> : If 结束<?php the_time(‟字符串‟) ?> : 显示时间,时间格式由“字符串”参数决定,具体参考PHP手册<?php comments_popup_link(); ?> : 正文中的留言链接。
完整的WordPress函数⼤全在修改和制作Wordpress主题时经常为不知道内置函数⽽苦恼,⽽wordpress官⽅的⽂档看起来⼜不是那么⽅便。
所搜集并且整理了⼀下放这,以备后⽤。
判断页⾯函数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函数<?php bloginfo(’name’); ?> : 博客名称(Title)<?php bloginfo(’stylesheet_url’); ?> : CSS⽂件路径<?php bloginfo(’pingback_url’); ?> : PingBack Url<?php bloginfo(’template_url’); ?> : 模板⽂件路径<?php bloginfo(’version’); ?> : WordPress版本<?php bloginfo(’atom_url’); ?> : Atom Url<?php bloginfo(’rss2_url’); ?> : RSS 2.o Url<?php bloginfo(’url’); ?> : 博客 Url<?php bloginfo(’html_type’); ?> : 博客⽹页Html类型<?php bloginfo(’charset’); ?> : 博客⽹页编码<?php bloginfo(’description’); ?> : 博客描述<?php wp_title(); ?> : 特定内容页(Post/Page)的标题模板常⽤的PHP函数及命令<?php get_header(); ?> : 调⽤Header模板<?php get_sidebar(); ?> : 调⽤Sidebar模板<?php get_footer(); ?> : 调⽤Footer模板<?php the_content(); ?> : 显⽰内容(Post/Page)<?php if(have_posts()) : ?> : 检查是否存在Post/Page<?php while(have_posts()) : the_post(); ?> : 如果存在Post/Page则予以显⽰<?php endwhile; ?> : While 结束<?php endif; ?> : If 结束<?php the_time(’字符串’) ?> : 显⽰时间,时间格式由“字符串”参数决定,具体参考PHP⼿册<?php comments_popup_link(); ?> : 正⽂中的留⾔链接。
导航菜单是每一个WordPress主题必须的元素,如果你要制作一个WordPress主题,那就必须熟悉WordPress导航菜单注册函数register_nav_menus() 和导航菜单调用函数wp_nav_menu() ,这两个参数一般都是配合使用的。
今天我们就一起来解释一下这两个函数,并举例说明。
导航菜单注册函数register_nav_menus() 介绍register_nav_menus() 是3.0以后用来注册自定义菜单的函数,通过它可以很方便地给你的主题注册一个或多个菜单,在主题的functions.php 中添加:1 2 3 4register_nav_menus( array('header_menu'=> 'My Custom Header Menu', 'footer_menu'=> 'My Custom Footer Menu') );上面的代码注册了两个代码,其中'header_menu' 和'footer_menu' 分别是这两个菜单的“键key”,而后面的'My Custom Header Menu' 和'My Custom Footer Menu' 是对这个菜单的描述,会在外观- 菜单中显示出来。
下文将会图例说明。
按照上面的结构,就可以注册多个菜单。
导航菜单调用函数wp_nav_menu() 介绍wp_nav_menu() 是WordPress 3.0 以后添加的一个自定义导航菜单调用函数,可用来调用register_nav_menus() 注册的菜单。
wp_nav_menu()的使用方法位于wp-includes/nav-menu-templates.php文件中。
可以通过<?php wp_nav_menu( $args ); ?> 来调用菜单,其中参数$args 的默认值如下:1 2 3 4 5 6 7 8 <?php$defaults= array('theme_location'=> '', 'menu'=> '', 'container'=> 'div', 'container_class'=> '','container_id'=> '',9101112131415161718192021222324 'menu_class'=> 'menu','menu_id'=> '','echo'=> true,'fallback_cb'=> 'wp_page_menu','before'=> '','after'=> '','link_before'=> '','link_after'=> '','items_wrap'=> '<ul id="%1$s" class="%2$s">%3$s</ul>', 'depth'=> 0,'walker'=> '');wp_nav_menu( $defaults);?>每个参数的详细介绍如下:$theme_locaton:(字符串)(可选)默认值: None用于在调用导航菜单时指定注册过的某一个导航菜单名,如果没有指定,则显示第一个。
WORDPRESS函数使用说明WordPress是一个非常流行的开源内容管理系统(CMS),它提供了丰富的功能和灵活的扩展性,使得用户可以轻松创建和管理自己的网站。
WordPress的功能主要是通过函数调用来实现的,函数提供了许多方便的方法来完成各种任务,包括创建页面、发布文章、添加插件、更改主题等。
在这篇文章中,我们将详细介绍一些常用的WordPress函数,以及它们的使用说明。
1. get_header(和get_footer(: 这两个函数用于在页面中引入网站的头部和底部。
可以将它们放置在页面的适当位置,以保证每个页面都有一致的布局和样式。
2. bloginfo(: 这个函数用于输出网站的基本信息,比如网站的名称、描述、URL等。
可以使用不同的参数来获取不同的信息,比如bloginfo('name')将输出网站的名称,bloginfo('description')将输出网站的描述。
3. wp_nav_menu(: 这个函数用于创建自定义菜单。
可以通过在WordPress后台创建菜单,并给菜单分配位置,然后使用wp_nav_menu(函数将菜单输出到指定位置。
4. get_sidebar(: 这个函数用于引入侧边栏的内容。
可以将它放置在页面的适当位置,以显示一些附加的信息、小工具或广告。
6. the_loop(: 这个函数用于循环输出查询结果。
通常配合wp_query(函数一起使用,可以在循环中使用其他函数来输出文章的标题、内容、缩略图等信息。
7. get_permalink(: 这个函数用于获取文章或页面的永久链接。
可以使用这个函数来生成自定义的链接,比如在文章列表中添加“阅读全文”链接。
8. the_title(和the_content(: 这两个函数分别用于输出文章或页面的标题和内容。
可以将它们放置在循环中,以逐个输出查询结果。
9. the_post_thumbnail(: 这个函数用于输出文章或页面的特色图像。
Wordpress Category分类函数、Tags标签函数详解对Wordpress进行模板和插件设计,当然少不了要了解Wordpress的函数,就像要用C++、Java少不了API一样。
本篇文章总结了Wordpress Category分类函数和Tags标签函数的使用方法。
目录模板函数集(Category Template Tags)(注意:所有代码的符号均需半角符号)一、获取文章目录链接(Post Category)函数-<?phpthe_category(’arguments’);?>,多参数。
参数说明:①分隔符(seperator),目录之间的分隔符号,可以为文字或字符,默认情况下按照无序列表的形式显示。
例子:<?php the_category('seperator=•');?>②层级参数(parents),如何显示子目录链接,属性值有single和multiple。
例子:<?php the_category('parents=multiple'); ?>二、在RSS中显示文章的发表目录(Post Category in RSS Format)函数-<?php the_category_rss(’arguments’); ?>。
参数说明:①类型(type):Feed显示类型。
例子:<?php the_category_rss('type=rss');?>三、获取页面目录名称函数(Page Category Title)函数-<?phpsingle_cat_title(’prefix’,'display’); ?>,显示或返回当前页面所属目录名称。
参数说明:①前缀(prefix),目录名称前缀,默认值:不显示任何内容。
例子:<?php single_cat_title('•','display');?>②显示目录名称参数(display)。
register_taxonomy用法register_taxonomy是WordPress中的一个函数,用于注册一个新的分类法(Custom Taxonomy)或修改一个现有的分类法。
通过调用此函数,您可以创建和管理自己的分类法,以便在WordPress中组织和分类内容。
register_taxonomy函数的语法如下:phpregister_taxonomy( $taxonomy, $object_type, $args = array() );函数的参数解释如下:$taxonomy(必需):自定义分类法的名称,用于在代码中引用。
字符串类型,不超过32个字符。
$object_type(必需):指定自定义分类法将应用于哪些对象类型(例如,文章、页面、自定义帖子类型等)。
可以是数组或字符串。
$args(可选):用于进一步配置自定义分类法的参数数组。
以下是一些可用的参数:labels:数组,用于定义分类法的标签。
例如,名称、单数名称、搜索项、所有项等。
description:字符串,用于提供分类法的简要描述。
public:布尔值,指定分类法是否允许通过管理界面或前端使用。
publicly_queryable:布尔值,指定分类法是否可以公开查询。
hierarchical:布尔值,指定分类法是否支持层级结构。
show_ui:布尔值,指定是否在后台管理中显示分类法。
show_in_menu:布尔值,指定是否在后台菜单中显示分类法。
show_in_nav_menus:布尔值,指定是否在导航菜单中显示分类法。
show_in_rest:布尔值,指定分类法是否在REST API中使用。
rest_base:字符串,更改REST API的基础路径。
rest_controller_class:字符串,指定REST API控制器类名。
show_tagcloud:布尔值,指定是否在标签云小工具中显示分类法。
show_in_quick_edit:布尔值,指定是否在快速/批量编辑模块中显示分类法。
wordpress函数⼤全列表整理wordpress有很多的函数可供调⽤,下⾯ytkah就整理了⼀下wordpress函数⼤全供各位参考,如果要详情,可以访问https:///reference/functions/参数名/,感兴趣的朋友可以收藏⽂章,页⾯,附件,书签⽂章get_adjacent_postget_boundary_postget_childrenget_extendedget_next_postget_next_posts_linknext_posts_linkget_permalinkthe_permalinkget_the_excerptthe_excerptget_the_post_thumbnailget_postget_post_fieldget_post_ancestorsget_post_mime_typeget_post_statusget_post_formatset_post_formatget_delete_post_linkget_previous_postget_previous_posts_linkprevious_posts_linkhave_postsis_post(不赞成)is_singleis_stickyget_the_IDthe_IDthe_postwp_get_recent_postswp_get_single_posthas_post_thumbnailhas_excerpthas_post_format⾃定义⽂章状态register_post_status⾃定义⽂章类型register_post_typeis_post_type_archivepost_type_archive_titleadd_post_type_supportremove_post_type_supportpost_type_supportsset_post_typepost_type_existsget_post_typeget_post_typesget_post_type_archive_linkget_post_type_objectget_post_type_capabilitiesget_post_type_labelsis_post_type_hierarchical⽂章插⼊/移除lwp_delete_postwp_insert_postwp_publish_postwp_trash_postwp_update_post页⾯get_all_page_idsget_ancestorsget_page(不赞成)get_page_linkget_page_by_pathget_page_by_titleget_page_childrenget_page_hierarchyget_page_uriget_pagesis_pagepage_uri_indexwp_link_pageswp_dropdown_pages⾃定义域 (⽂章信息 postmeta)add_post_metadelete_post_metaget_post_customget_post_custom_keysget_post_custom_valuesget_post_metaupdate_post_metaregister_meta附件get_attached_fileimage_resize(不赞成)is_attachmentis_local_attachmentset_post_thumbnailupdate_attached_filewp_attachment_is_imagewp_create_thumbnail(不赞成)wp_insert_attachmentwp_delete_attachmentwp_get_attachment_imagewp_get_attachment_linkwp_get_attachment_image_srcwp_get_attachment_metadatawp_get_attachment_thumb_filewp_get_attachment_thumb_urlwp_get_attachment_urlwp_check_for_changed_slugswp_count_postswp_get_mime_typeswp_mime_type_iconwp_generate_attachment_metadata wp_prepare_attachment_for_jswp_update_attachment_metadata 书签(链接)get_bookmarkget_bookmarkswp_get_post_categories条件项wp_set_post_categorieswp_get_post_tagswp_set_post_tagswp_get_post_termswp_set_post_termswp_count_termshas_termis_object_in_term其他add_meta_boxremove_meta_boxget_the_IDthe_IDget_the_authorthe_authorget_the_author_posts get_the_contentthe_contentget_the_titlethe_titlethe_title_attributewp_trim_excerptwp_get_post_revision wp_get_post_revisions wp_is_post_revision paginate_links分类,标签,分类法分类cat_is_ancestor_ofget_all_category_idsget_ancestorsget_cat_IDget_cat_nameget_categoriesget_categoryget_category_by_path get_category_by_slug get_the_category_by_ID get_the_category_list get_category_linkget_category_parents get_the_categorysingle_cat_titlein_categoryis_categorythe_categorywp_category_checklist wp_dropdown_categories wp_list_categories分类创建wp_create_categorywp_delete_categorywp_insert_category标签get_tagget_tag_linkget_tagsget_the_tag_listget_the_tagshas_tagis_tagthe_tagssingle_tag_titletag_descriptionwp_generate_tag_cloud wp_tag_cloud分类法get_object_taxonomiesget_edit_term_linkget_edit_term_linkget_taxonomyget_taxonomiesget_termget_the_term_listget_term_bythe_termsget_the_termsget_term_childrenget_term_linkget_termsis_taxonomyis_taxonomy_hierarchicalis_term(不赞成)taxonomy_existsterm_existsregister_taxonomyregister_taxonomy_for_object_type wp_get_object_termswp_remove_object_termswp_set_object_termswp_insert_termwp_update_termwp_delete_termwp_terms_checklist⽤户、作者及权限权限add_capadd_roleauthor_cancurrent_user_cancurrent_user_can_for_blogget_roleget_super_adminsis_super_adminmap_meta_capremove_capremove_roleuser_can⽤户和作者auth_redirectcount_userscount_user_postscount_many_users_postsemail_existsget_currentuserinfoget_current_user_idget_profile(不赞成)get_user_byget_userdataget_usernumposts(不赞成)get_usersset_current_user(不赞成)user_pass_ok(不赞成)wp_authenticateusername_existsvalidate_usernamewp_dropdown_userswp_get_current_userwp_set_current_userwp_set_passwordget_author_posts_urlget_the_modified_authoris_multi_author⽤户 metaadd_user_metadelete_user_metaget_user_metaupdate_user_metaget_the_author_meta⽤户添加和删除wp_create_userwp_delete_userwp_insert_userwp_update_user登录和注销is_user_logged_inwp_login_formwp_signonwp_logoutwp_loginout供稿(Feed)bloginfo_rsscomment_author_rsscomment_linkcomment_text_rssdo_feeddo_feed_atomdo_feed_rdfdo_feed_rssdo_feed_rss2fetch_feedfetch_rss(不赞成)get_author_feed_linkget_bloginfo_rssget_category_feed_linkget_comment_linkget_comment_author_rssget_post_comments_feed_link get_rss(不赞成)get_search_comments_feed_link get_search_feed_linkget_the_category_rssget_the_title_rsspost_comments_feed_linkrss_enclosurethe_title_rssthe_category_rssthe_content_rss(不赞成)the_excerpt_rsswp_rss(不赞成)评论,通知和引⽤(Ping,Trackback) add_pingadd_comment_metacheck_commentcomment_textcomment_formcomments_numberdiscover_pingback_server_uri delete_comment_metado_all_pingsdo_enclosedo_trackbacksgeneric_pingget_approved_commentsget_avatarget_commentget_comment_textget_comment_metaget_commentswp_list_commentsget_enclosedget_lastcommentmodifiedget_pungget_to_pinghave_commentsget_comment_authoris_trackbackpingbackprivacy_ping_filtersanitize_comment_cookies trackbacktrackback_urltrackback_url_listupdate_comment_metaweblog_pingwp_allow_commentwp_count_commentswp_delete_commentwp_filter_commentwp_get_comment_statuswp_get_current_commenterwp_insert_commentwp_new_commentwp_set_comment_statuswp_throttle_comment_floodwp_update_commentwp_update_comment_countwp_update_comment_count_now 评论循环comment_classcomment_IDcomment_authorcomment_datecomment_timeget_comment_dateget_comment_time评论分页paginate_comments_links previous_comments_linknext_comments_linkget_comment_pages_count远程(remote)wp_remote_getwp_remote_retrieve_bodywp_get_http_headerswp_remote_fopen动作(Action),过滤器(Filter)和插件过滤器has_filteradd_filterapply_filtersapply_filters_ref_arraycurrent_filtermerge_filtersremove_filterremove_all_filters动作has_actionadd_actiondo_actiondo_action_ref_arraydid_actionremove_actionremove_all_actions插件plugin_basenameplugins_urlget_plugin_dataget_admin_page_titleplugin_dir_pathregister_activation_hookregister_deactivation_hookmenu_page_urlis_plugin_activeis_plugin_active_for_networkis_plugin_inactiveis_plugin_pageadd_contextual_help(不赞成)get_plugins⼩⼯具is_active_widgetregister_widgetthe_widgetunregister_widgetwp_add_dashboard_widgetwp_convert_widget_settingswp_get_sidebars_widgets(不赞成)wp_get_widget_defaultswp_register_sidebar_widgetwp_register_widget_controlwp_set_sidebars_widgets(不赞成)wp_unregister_sidebar_widgetwp_unregister_widget_controlwp_widget_description设置register_settingunregister_settingsettings_fieldsdo_settings_fieldsdo_settings_sectionsadd_settings_fieldadd_settings_sectionadd_settings_errorget_settings_errorssettings_errors短标签add_shortcodedo_shortcodedo_shortcode_tag(不赞成)get_shortcode_regexremove_shortcoderemove_all_shortcodesshortcode_attsshortcode_parse_attsstrip_shortcodes主题相关Include 函数comments_templateget_footerget_headerget_sidebarget_search_form其他函数add_custom_backgroundadd_custom_image_header(不赞成)add_image_sizeadd_theme_supportbody_classcurrent_theme_supportsdynamic_sidebarget_404_templateget_archive_templateget_attachment_templateget_author_templateget_body_classget_category_templateget_comments_popup_templateget_current_themeget_date_templateget_header_imageget_header_textcolorget_home_templateget_locale_stylesheet_uriget_page_templateget_paged_templateget_post_classget_query_templateget_search_templateget_single_templateget_stylesheetget_stylesheet_directoryget_stylesheet_directory_uriget_stylesheet_uriget_tag_templateget_taxonomy_templateget_templateget_template_directoryget_template_directory_uriget_template_partget_theme(不赞成)wp_get_themesget_theme_data(不赞成)get_theme_supportget_theme_modget_theme_modsget_theme_rootget_theme_rootsget_theme_root_uriget_themes(不赞成)has_header_imageheader_imageheader_textcolorin_the_loopis_child_themeis_active_sidebaris_admin_bar_showingis_customize_previewis_dynamic_sidebarlanguage_attributesload_templatelocale_stylesheetlocate_templatepost_classpreview_themepreview_theme_ob_filter preview_theme_ob_filter_callback register_nav_menuregister_nav_menusget_registered_nav_menuswp_create_nav_menuregister_sidebarregister_sidebarsregister_theme_directory remove_theme_modremove_theme_modsremove_theme_supportrequire_if_theme_supports search_theme_directoriesset_theme_modswitch_themevalidate_current_theme unregister_nav_menu unregister_sidebarwp_add_inline_stylewp_clean_themes_cachewp_get_archiveswp_get_nav_menu_itemswp_get_themewp_nav_menuwp_oembed_remove_provider wp_page_menuwp_title格式化(Formatting)absintadd_magic_quotes addslashes_gpcantispambotattribute_escapebackslashitbalanceTagsclean_preclean_url(不赞成)convert_charsconvert_smiliesent2ncresc_attresc_htmlesc_jsesc_textareaesc_sqlesc_urlesc_url_rawforce_balance_tagsformat_to_editformat_to_post(不赞成)funky_javascript_fix htmlentities2is_emailjs_escape(不赞成)make_clickablepopuplinksremove_accentssanitize_emailsanitize_file_namesanitize_html_classsanitize_keysanitize_mime_type sanitize_optionsanitize_sql_orderby sanitize_text_fieldsanitize_titlesanitize_title_for_query sanitize_title_with_dashes sanitize_userseems_utf8stripslashes_deep trailingslashit untrailingslashiturlencode_deepurl_shortenutf8_uri_encodewpautopwptexturizewp_filter_kseswp_filter_post_kseswp_filter_nohtml_kseswp_iso_descramblerwp_kseswp_kses_array_lcwp_kses_attrwp_kses_bad_protocolwp_kses_bad_protocol_once wp_kses_bad_protocol_once2 wp_kses_check_attr_valwp_kses_decode_entitieswp_kses_hairwp_kses_hookwp_kses_html_errorwp_kses_js_entitieswp_kses_no_nullwp_kses_normalize_entities wp_kses_normalize_entities2 wp_kses_splitwp_kses_split2wp_kses_strip_slasheswp_kses_versionwp_make_link_relativewp_normalize_pathwp_rel_nofollowwp_richedit_prewp_specialcharswp_trim_wordszeroisecurrent_timedate_i18nget_calendarget_date_from_gmtget_lastpostdateget_lastpostmodifiedget_day_linkget_gmt_from_dateget_month_linkthe_dateget_the_datethe_timeget_the_timethe_modified_timeget_the_modified_timeget_weekstartendget_year_linkhuman_time_diffiso8601_timezone_to_offset iso8601_to_datetime mysql2date序列化is_serializedis_serialized_string maybe_serializemaybe_unserialize选项add_optionadd_site_optiondelete_optiondelete_site_optionform_optionget_alloptions(不赞成)get_site_optionget_site_urlget_admin_urlget_user_optionget_optionupdate_optionupdate_site_option update_user_optionwp_load_alloptions Transientsset_transientget_transientdelete_transientset_site_transientget_site_transientdelete_site_transient后台菜单add_menu_pageremove_menu_pageadd_submenu_page remove_submenu_page add_object_pageadd_utility_pageadd_comments_pageadd_dashboard_pageadd_links_pageadd_management_page add_media_pageadd_options_pageadd_pages_pageadd_plugins_pageadd_posts_pageadd_theme_pageadd_users_page⼯具栏add_groupget_nodeget_nodes表单帮助checkeddisabledselectedsubmit_buttonget_submit_buttonNonces and Refererscheck_admin_referercheck_ajax_refererwp_create_noncewp_explain_nonce(不赞成)wp_get_original_refererwp_get_refererwp_nonce_ayswp_nonce_fieldwp_nonce_urlwp_original_referer_fieldwp_referer_fieldwp_send_jsonwp_send_json_errorwp_send_json_successwp_verify_nonceXMLRPCxmlrpc_getpostcategory xmlrpc_getposttitlexmlrpc_removepostdatauser_pass_ok(不赞成)本地化___x_n_nx_e_ex__ngettextesc_attr__esc_attr_eget_localeload_default_textdomain load_plugin_textdomainload_textdomainload_theme_textdomainis_rtl定时spawn_cronwp_clear_scheduled_hook wp_cronwp_get_schedulewp_get_scheduleswp_next_scheduledwp_reschedule_eventwp_schedule_eventwp_schedule_single_event wp_unschedule_eventwp_dequeue_scriptwp_dequeue_stylewp_deregister_scriptwp_deregister_stylewp_enqueue_scriptwp_enqueue_stylewp_localize_scriptwp_register_scriptwp_register_stylewp_script_iswp_style_isSQLget_tax_sqlget_meta_sqlget_posts_by_author_sql杂项add_editor_styleadd_query_argadmin_urlbool_from_yncache_javascript_headers capital_P_dangitclean_blog_cachecontent_urldo_robotsflush_rewrite_rulesget_bloginfoget_num_queriesget_post_statiget_post_statusesget_query_varhome_urlincludes_urlis_blog_installedis_main_siteis_main_queryis_multisiteis_sslis_wp_errorlog_app(不赞成)make_url_footnote(不赞成)network_admin_url network_home_urlnetwork_site_urlnocache_headersplugin_dir_urlquery_postsremove_query_argrewind_postssetup_postdatasite_urlstatus_headerunzip_filevalidate_filevalidate_file_to_editwpwp_cache_setwp_cache_getwp_cache_reset(不赞成)wp_check_filetypewp_clearcookiewp_diewp_editorwp_footerwp_get_cookie_login(不赞成)wp_get_image_editorwp_get_installed_translationswp_hashwp_handle_sideloadwp_headwp_install_defaultswp_is_mobilewp_mailwp_mkdir_pwp_new_user_notificationwp_password_change_notificationwp_notify_moderatorwp_notify_postauthorwp_parse_argswp_redirectwp_reset_postdatawp_reset_querywp_saltwp_set_auth_cookiewp_safe_redirectwp_upload_bitswp_upload_dirwp_list_pluckwp_text_diffpost_submit_meta_boxpings_openis_page_templateis_authorlike_escape多站点管理员confirm_delete_usersis_user_member_of_blogwp_dashboard_quotaadmin_notice_feed(不赞成)avoid_blog_page_permalink_collision check_import_new_userscheck_upload_sizechoose_primary_blogdisplay_space_usagefix_import_form_sizeformat_code_langget_site_allowed_themesgrant_super_adminms_deprecated_blogs_filemu_dropdown_languagesnew_user_email_admin_noticeredirect_user_to_blogrefresh_user_detailsrevoke_super_adminsecret_salt_warningsend_confirmation_on_profile_email show_post_thumbnail_warning(不赞成)site_admin_noticesync_category_tag_slugsupdate_option_new_admin_email update_user_statusupload_is_user_over_quotaupload_space_settingwpmu_delete_blogwpmu_delete_userwpmu_get_blog_allowedthemes_admin_notice_multisite_activate_plugins_page 其他⽅法add_blog_optiondelete_blog_optionget_blogaddress_by_domainget_blogaddress_by_idget_blogaddress_by_nameget_blog_detailsget_blog_optionget_blog_statusget_id_from_blognameget_last_updatedis_archivedrefresh_blog_detailsrestore_current_blogswitch_to_blogupdate_archivedupdate_blog_detailsupdate_blog_optionupdate_blog_statuswpmu_update_blogs_datems_cookie_constantsms_file_constantsms_subdomain_constantsms_upload_constantsadd_existing_user_to_blogadd_new_user_to_blogadd_user_to_blogcheck_upload_mimescreate_empty_blogdomain_existsfilter_SSLfix_phpmailer_messageidforce_ssl_contentget_active_blog_for_userget_admin_users_for_domainget_blogs_of_userget_blog_countget_blog_id_from_urlget_blog_permalinkget_blog_postget_current_siteget_dashboard_blogget_dirsizeget_most_recent_post_of_userget_sitestatsget_space_allowedget_space_usedget_upload_space_availableget_user_countget_user_id_from_string(不赞成)global_termsinsert_bloginstall_bloginstall_blog_defaultsis_blog_user(不赞成)is_email_address_unsafeis_upload_space_availableis_user_option_localis_user_spammymaybe_add_existing_user_to_blogmaybe_redirect_404newblog_notify_siteadminnewuser_notify_siteadminrecurse_dirsizeredirect_this_siteremove_user_from_blogsignup_nonce_checksignup_nonce_fieldsupdate_blog_publicupdate_posts_countupload_is_file_too_bigupload_is_user_over_quota upload_size_limit_filterusers_can_register_signup_filter welcome_user_msg_filterwp_get_siteswpmu_activate_signupwpmu_create_blogwpmu_create_userwpmu_log_new_registrations wpmu_signup_blogwpmu_signup_blog_notification wpmu_signup_userwpmu_signup_user_notification wpmu_validate_blog_signup wpmu_validate_user_signup wpmu_welcome_notification wpmu_welcome_user_notification get_current_site_name(不赞成)is_subdomain_installms_not_installedms_site_checkwpmu_current_site(不赞成)。
系统闭环传递函数标准形式:取ζ分别取0,0.1,0.5,0.707,1,3,7进行matlab分析Matlab代码:>> zeta1=0;num1=[4];den1=[4 0 4];>> sys1=tf(num1,den1); %建立ζ=0时闭环传递函数模型>> p1=roots(den1) %计算系统特征根判断系统稳定性p1 =0 + 1.0000i0 - 1.0000i>> t=0:0.05:10; %设定仿真时间为10s>> y1=step(sys1,t); %求取ζ=0时系统的单位阶跃响应>> zeta2=0.1;num2=[4];den2=[1 0.4 4];>> sys2=tf(num2,den2); %建立ζ=0.1时闭环传递函数模型>> p2=roots(den2)p2 =-0.2000 + 1.9900i-0.2000 - 1.9900i>> y2=step(sys2,t); %求取ζ=0.1时系统的单位阶跃响应>> zeta3=0.5;num3=[4];den3=[1 2 4];>> sys3=tf(num3,den3); %建立ζ=0.5时闭环传递函数模型>> p3=roots(den3)p3 =-1.0000 + 1.7321i-1.0000 - 1.7321i>> y3=step(sys3,t); %求取ζ=0.5时系统的单位阶跃响应>> zeta4=0.707;num4=[4];den4=[1 2.828 4];>> sys4=tf(num4,den4); %建立ζ=0.707时闭环传递函数模型>> p4=roots(den4)p4 =-1.4140 + 1.4144i-1.4140 - 1.4144i>> y4=step(sys4,t); %求取ζ=0.707时系统的单位阶跃响应>> zeta5=1;num5=[4];den5=[1 4 4];>> sys5=tf(num5,den5); %建立ζ=1时闭环传递函数模型>> p5=roots(den5)p5 =-2-2>> y5=step(sys5,t); %求取ζ=1时系统的单位阶跃响>> zeta6=3;num6=[4];den6=[1 12 4];>> sys6=tf(num6,den6); %建立ζ=3时闭环传递函数模型>> p6=roots(den6)p6 =-11.6569-0.3431>> y6=step(sys6,t); %求取ζ=3时系统的单位阶跃响>> zeta7=7;num7=[4];den7=[1 28 4];>> sys7=tf(num7,den7); %建立ζ=7时闭环传递函数模型>> p7=roots(den7)p7 =-27.8564-0.1436>> y7=step(sys7,t); %求取ζ=7时系统的单位阶跃响>> plot(t,y1,'-y',t,y2,'-m',t,y3,'-c',t,y4,'-r',t,y5,'-g',t,y6,'-b',t,y7,'-k')%画出单位脉冲响应曲线>> grid>> xlabel('t');ylabel('c(t)');title('step response');。
get_terms函数get_terms函数是WordPress中一个非常有用的函数,它用于获取分类和标签的信息。
在本文中,我将介绍get_terms函数的基本用法以及一些常见的应用场景。
1. 基本用法get_terms函数的基本用法如下:```$terms = get_terms( $args );```其中,$args是一个可选的参数数组,用于指定获取分类和标签的条件。
如果不传递$args参数,则默认获取所有分类和标签。
2. 获取分类要获取分类的信息,可以使用以下代码:```$categories = get_terms( 'category' );```这样,$categories变量将包含所有分类的信息。
可以通过循环遍历的方式来输出每个分类的名称、链接等信息。
3. 获取标签要获取标签的信息,可以使用以下代码:```$tags = get_terms( 'post_tag' );```这样,$tags变量将包含所有标签的信息。
同样地,可以通过循环来输出每个标签的相关信息。
4. 限制数量有时候,我们只希望获取一定数量的分类或标签。
可以通过设置$args数组中的'number'参数来实现。
例如,要获取5个分类,可以使用以下代码:```$categories = get_terms( array('taxonomy' => 'category','number' => 5,) );```5. 按父级分类获取如果希望只获取某个父级分类下的子分类,可以使用'parent'参数。
例如,要获取分类ID为2的父级分类下的子分类,可以使用以下代码:```$categories = get_terms( array('taxonomy' => 'category','child_of' => 2,) );```6. 按分类别名获取有时候,我们可能通过分类的别名来获取分类的信息。
WordPress数据库操作函数详解_为了便于访问数据库,WordPress供应了一个友好的数据库操作类:wpdb,该类定义在/wp-includes/wp-db.php 文件中。
wpdb类封装了全部的数据库操作函数,它是基于开源的数据库操作类ezSQL进行修改的,使其更适合于WordPress,也使其仅适用于mySQL数据库。
同时,WordPress 还供应了一个全局变量$wpdb,并将其实例化为wpdb类的对象。
这样我们就可以挺直用法$wpdb来调用全部的数据库操作函数。
通过这个$wpdb对象,我们可以对WordPress数据库进行任何操作,包括建表、查询、删除、更新等。
要留意的是,假如要在自定义函数中用法$wpdb,必需先将其全局化(global $wpdb;)。
下面就具体介绍一下WordPress的数据库操作函数:1、function query($query)这个函数是最基本的数据库操作函数,$query为SQL语句,提交给数据库执行,结果分两种状况:1). 假如是“insert|delete|update|replace”,返回受影响行数,在“insert|replace”这种状况下,该函数会用$this-insert_id记录下新插入的ID。
2). 假如是“select”,该函数会用$this-last_result记录下查询到结果集,返回查询到的记录行数。
假如出错,则返回FALSE。
实例:?php$wpdb-query("UPDATE $wpdb-postsSET post_parent = 7WHERE ID = 15 AND post_status = 'static'");?2、function escape($data)用法反斜线引用数据,也就是用法魔术引号。
实例:?php$name = $wpdb-escape($name);$email = $wpdb-escape($email);$wpdb-query("INSERT INTO myusers (id, name, email) VALUES (NULL, '$name', '$email')");?3、function insert($table, $data, $format = null)这是插入记录函数,第一个参数是表的字段数组,其次个是数据数组,第三个用于规定$data中每个值的数据类型。
WordPress模板页⾯判断函数Index page ⾸页is_home()判断是否为⾸页.The Front Page ⾸页头版消息设置is_front_page()判断是否为⾸页头版消息. (⽆论是⽇志或是页⾯).当系统显⽰博客主页且管理⾯板的设置>阅读菜单下 “主页显⽰为”选项设为最近发表的⽂章”,或者’设置>阅读菜单下”主页显⽰为”选项设为且”主页”是当前被显⽰的页⾯时,is_front_page() 标签返回TRUE。
The Administration Panels 管理控制⾯板is_admin()判断是否为后台管理控制⾯板.A Single Post Page 单篇⽇志is_single()判断是否为任何单篇⽇志.is_single(’17′)判断是否为ID17的单篇⽇志.is_single(‘Irish Stew’)判断是否标题为”Irish Stew”的单篇⽇志.is_single(‘beef-stew’)判断是否别名为 “beef-stew”的单篇⽇志.is_single(array(17,’beef-stew’,’Irish Stew’))判断是否为ID17, 或别名为”beef-stew”, 或标题为 “Irish Stew”的单篇⽇志.is_single(array(17, 19, 1, 11))判断是否为ID 17, 19, 1, 11 的⽂章.is_single(array(‘beef-stew’, ‘pea-soup’, ‘chili’))判断是否别名为 “beef-stew”, 别名为 “pea-soup” 或别名为 “chili” 的单篇⽇志.is_single(array(‘Beef Stew’, ‘Pea Soup’, ‘Chili’))判断是否标题为 “Beef Stew”,标题为 “Pea Soup” 或标题为 “Chili” 的单篇⽇志.A Sticky Post 置顶⽂章is_sticky()判断是否为置顶⽂章.is_sticky(’17′)判断是否为ID17的置顶⽂章.A Comments Popup 评论的弹出窗⼝is_comments_popup()判断是否为评论的弹出窗⼝.Any Page Containing Posts 评论comments_open()判断当前⽂章是否允许评论.pings_open()判断当前⽂章是否允许⼴播(pingback).A PAGE Page 页⾯is_page()判断是否任何页⾯.is_page(’42′)判断是否ID 42的页⾯.is_page(‘About Me And Joe’)判断是否标题为”About Me And Joe” 的页⾯.is_page(‘about-me’)判断是否别名为 “about-me” 的页⾯.is_page(array(42,’about-me’,’About Me And Joe’))判断是否为 ID 42, 或别名 “about-me”, 或标题 “About Me And Joe” 的页⾯.A Category Page 分类归档is_category()判断是否为任何分类页.is_category(’9′)判断是否为ID9的分类页.is_category(‘Stinky Cheeses’)判断是否名称为 “Stinky Cheeses”的分类归档页.is_category(‘blue-cheese’)判断别名是否为 “blue-cheese”的分类归档页.is_category(array(9,’blue-cheese’,’Stinky Cheeses’))判断是否ID为 9, 或者别名为 “blue-cheese”, 或者名称为 “Stinky Cheeses”的分类归档页.in_category(’5′)判断当前⽂章的分类ID是否为5in_category( array( 1,2,3 ) )判断当前⽂章的分类ID是否为 1, 2, 或 3.!in_category( array( 4,5,6 ) )判断当前⽂章的分类ID是否不是 4, 5, 或 6 .A Tag Page 标签归档is_tag()判断是否为标签页is_tag(‘mild’)判断是否为别名 ‘mild’ 的标签归档页.is_tag(array(‘sharp’,’mild’,’extreme’))判断别名是否为 “sharp”, “mild”, 或 “extreme” 的标签归档页.has_tag()判断当前⽂章是否有标签.has_tag(‘mild’)判断当前⽂章是否有标签 ‘mild’.has_tag(array(‘sharp’,’mild’,’extreme’))判断当前⽂章是否包含⼀个数组中的标签.An Author Page 作者归档is_author()判断是否为作者归档页.is_author(’4′)判断是否为ID4的作者归档页.is_author(‘Vivian’)判断是否为昵称 “Vivian”的作者归档页.is_author(‘john-jones’)判断是否为昵称 “john-jones” 的作者归档页.is_author(array(4,’john-jones’,’Vivian’))判断是否为 ID 4, 或者昵称 “john-jones”, 或昵称 “Vivian” 的作者标签页.A Date Page ⽇期归档页is_date()判断是否为⽇期归档页.is_year()判断是否为按年归档页.is_month()When a monthly archive is being displayed.is_day()判断是否为按天归档页.is_time()判断是否按⼩时, “分钟”, “秒”归档页.Any Archive Page 归档页is_archive()是否归档页.A Search Result Page 搜索结果页is_search()是否搜索页.A 404 Not Found Page 未找到页⾯is_404()是否404页⾯.A Paged Page 分页is_paged()判断是否有分页. 需要将 <!–nextpage–> 快速标签插⼊到⽂章中才能将⽂章分成多页.An Attachment 附件is_attachment()判断是否为附件⽂档. 附件是通过编辑器上传⼯具上传的图⽚或其他⽂件. 附件能显⽰在相应的页⾯或模版中.A Single Page, Single Post or Attachment 独⽴页⾯、单篇⽇志或附件is_feed()⽹站需要使⽤RSS订阅时,is_feed()返回TRUE。
WordPress是目前十分流行的独立博客程序,因傻瓜化安装和使用,其在网民中的应用已近乎普及。
但也因为很多新入门的用户几乎对 WordPress程序没有任何了解,造成使用中碰到问题无法解决,求助也十分不易。
而且,根据月夜的经验,WordPress用户学习了解并掌握一些基本的WordPress知识尤其是WordPress中功能强大使用方便的函数会极大地方便自己的应用,从而定制一个自己心仪的独立博客。
在这一系列文章中,月夜试着将自己在长期的WordPress生涯中摸索积累的WordPress函数以自己的语言与朋友们分享,希望这一系列文章能够为朋友们使用WordPress程序带来方便。
在讲述下面的WordPress函数之前,我们需要明确这样一点,所有的WordPress函数都是已经定义好的PHP函数,它们都需要写在PHP 语句中(<?php ?>)才能执行;而且,所有这些函数在PHP语句中都应以分号”;”结尾。
其实,为了用好这些函数,为你的WordPress服务,你最好具有 PHP语言的基础。
1.bloginfo()顾名思义,该函数主要用来显示博客信息;而且根据参数的不同,可以用来显示博客信息中的不同部分。
常用的有以下几种:bloginfo(’name’) 显示博客题名,如“月夜”;默认(不写参数)输出该项;bloginfo(’description’) 显示博客描述部分,如“分享网络知识·享受快乐生活”;bloginfo(’url’) 输出博客URL地址,如;bloginfo(’rss2_url’) 显示博客的RSS2.0 feed地址,如/feed;bloginfo(’template_url’) 用来获取WordPress博客的模板地址;bloginfo(’charset’) 显示博客的编码方式,如“UTF-8”;一种常见的使用bloginfo()函数的组合如下:<a href=”<?php bloginfo(’url’); ?>” title=”<?phpbloginfo(’description’); ?>” ><?php bloginfo(’name’); ?>在月夜博客中,如上信息输出形如月夜的样式。
这种形式通常会用来添加博客的底部信息,如Copyright @ 月夜,经常在主题模板中使用。
需要注意的是bloginfo()函数只能输出显示这些参量,如果你想在PHP语句中使用得到的这些值,则需使用get_bloginfo()函数,该函数和bloginfo()使用相同的参数,获得相同的结果。
2.wp_title()该函数用来显示页面的标题,如在文章页面,则显示文章标题;在分类页面,则显示分类名称;等等。
wp_title()函数可以跟三个参数,即wp_title(’separator’,echo,seplocation),其中 separator是title和其余部分之间的分割符号,默认是>>;echo是个bool变量,取true显示标题,取false则将标题作为一个PHP参量返回;seplocation定义分隔符的位置,取right定义分隔符在标题后面,取其他任何值,都表示将分隔符放在标题前面。
比如形如主题文件夹下header.php中的一段代码:<title><?php wp_title(’ | ‘,true,’right’); ?><?php bloginfo(’name’); ?> - <?php bloginfo(’description’); ?></title>在博客首页可以显示这样的效果“月夜 - 分享网络知识·享受快乐生活”;在文章页,可以显示这样的效果“用好WordPress不可不知的50个函数 | 月夜 - 分享网络知识·享受快乐生活”;而在分类页面,则可以显示这样的效果“网站相关 | 月夜 - 分享网络知识·享受快乐生活”;等等。
3.wp_get_archives()该函数用来获取博客的文章存档,通过设置函数的参数,可以按各种方式获取,如按月,按年等等。
wp_get_archives()函数后面同样可以跟多种参数,只不过所有参数都需要使用&连接,并放在单引号(’)中以字符串方式传递给函数,形如wp_get_archives(’type=monthly&format=html&show_post_count=1&limit=10′)。
如上的参数意义描述如下:type=monthly表示按月显示文章存档,可以使用yearly、daily、weekly等代替monthly表示按年、日、以及周显示文章存档;format=html表示使用通常的HTML中<li>格式化文章列表;show_post_count=1表示在文章存档后面显示属于该类别(年、月等)的文章数量,该参量是个bool值;limit=10表示显示的文章存档的最大数量为10,超过次数,则超出部分不显示;尽管参数稍多,显得略为复杂,但其实只需注意type、show_post_count以及limit等三个参量即可。
4.wp_list_categories()和wp_get_archives()函数类似,wp_list_categories()函数用来获取博客文章的分类信息,并可以通过设置适当的函数参数,将其显示出来。
该函数的参数和wp_get_archives()函数类似,都需要使用&连接,放在单引号(’)中以字符串方式传递。
形如wp_get_archives(’orderby=name&order=ASC&show_count=1&use_desc_for_title=1&feed=订阅&exclude=2,5&number=10′)。
如上示例中,函数各参数的意义如下:orderby=name表示按照分类名称的字母先后顺序显示分类信息,可以将name换为ID等;order=ASC表示按照分类名称的字母的升序显示分类信息,将ASC改为DESC表示按降序;show_count=1在每个分类名称后面显示属于该分类的文章数;use_desc_for_title=1使用该分类的描述信息为每个分类名称超链接添加一个title属性;feed=订阅:在每个分类信息旁边添加一个名为“订阅”的超链接,提供该分类的RSS订阅;exlude=2,5:在显示的分类中去除ID为2和5的分类;也可以用include=2,5表示只显示ID为2和5的分类;number=10:表示只显示最先的10个分类。
5.get_the_category()get_the_category()函数用来返回当前文章所属的类别的若干属性所组成的一个数组,该数组包括以下内容:cat_ID:当前类别的ID(也可以写作’term_id’);cat_name:当前类别的名称(也被写作’name’);category_description:当前分类的描述(也可以写作’description’);category_count:属于当前分类的文章数量(也被写作’count’)。
具体的使用方法,我们通过下面的几个句子来说明:形如get_the_category()->cat_ID的语句,返回当前文章所属分类的ID号;形如get_the_category()->description的语句,返回当前文章所属分类的描述;等等。
6.the_category()该函数返回当前文章所属的类别名称,而且是文章类别的超链接形式。
默认的无参数形式the_category()直接以超链接形式显示类别名称,显示为:精品推介;可以在函数中跟上分隔符等参数来格式化输出,如the_category(’-'),若当前文章属于两个以上分类,可以显示这样的形式:精品推介-经验知识;如只属于一个分类,则显示为这样的形式:精品推介。
7.category_description()该函数以分类的ID为输入,得到该分类的描述。
常和echo、get_the_category()配合使用,将当前分类描述输出:echo category_description(get_the_category()->cat_ID);如上语句,get_the_category()得到保存有当前分类信息的一个数组;cat_ID 为该数组中该分类的ID;将该ID输入给category_description()函数,即可得到该分类的描述;然后使用echo将其输出。
但经月夜试验,使用如下的语句可以实现和上面语句相同的功能:echo category_description();这可能是因为该函数在默认无参数输入的情况下会输出当前分类描述的结果吧。
8.is_home()is_home()用以判断当前显示的博客页面是否是博客首页,返回的是一个Bool 值。
如果是在首页,则返回TRUE;否则返回FALSE。
该函数常用来控制博客侧边栏的显示方式,经常使用如下代码段:<?phpif ( is_home() ) {//此为在博客首页应该显示的内容} else {//此为非博客首页应该显示的内容}?>9.is_archive()is_archive()用以判断当前显示的内容是否是博客存档页面,比如按日期的存档,或者按分类的存档,等等;其和is_home()函数一样,返回一个Bool值。
10.is_page()is_page()函数判断当前显示的内容是否是博客的独立页面(page),如“月夜私语”、“关于月夜”等页面;它也返回一个Bool值。
我们可以在模板中通过该函数判断当前是否是一个独立页面,从而决定是否为当前显示的文章显示发布时间等等。
11.is_paged()该函数用以判断当前文章是否因为内容过多而分页显示;需要注意的是,如果你在写文章时手动添加了<!–nextpage–>标签,来强制分页的话,该函数并不会因此而返回TRUE。
12.is_page_template()is_page_template()函数需要跟一个参数,通常以如下方式使用:is_page_template(’guestbook.php’);藉此判断当前显示的独立页面(page)是否使用了参数所示的模板guestbook.php;如果不跟参数,函数返回当前独立页面是否使用了模板。
13.is_single()is_single()用以判断当前显示的页面内容是否是一篇单独的文章。