WordPress创建分类函数:wp_create_category
WordPress函数wp_create_category用于创建分类,创建成功返回分类的ID,失败返回WP_Error对象,如果分类已存在则返回该分类的ID。 wp_create_category( int|string $cat_name, int $parent ) 函数参数$cat_name …
WordPress函数wp_create_category用于创建分类,创建成功返回分类的ID,失败返回WP_Error对象,如果分类已存在则返回该分类的ID。 wp_create_category( int|string $cat_name, int $parent ) 函数参数$cat_name …
与get_cat_ID()函数相反,WordPress函数get_cat_name是根据分类ID获取分类名称。 get_cat_name( int $cat_id ) 函数参数$cat_id 整数 分类的ID 函数使用示例echo get_cat_name(6); 扩展阅读get_cat_name()函数位于:wp-includes/category.php 相关函数: get_cat_ID() get_term_by() get_category() get_term() get_category_children() get_category_by_slug() get_category_by_path() …
WordPress函数get_cat_ID可以根据分类的名称返回分类ID,在主题和插件的开发中很常用。 get_cat_ID( string $cat_name ) 函数参数$cat_name 字符串 分类的名称 函数使用示例$cat_ID = get_cat_ID('开发'); $category = get_category($cat_ID); echo '<a href="' . get_category_link($category->cat_ID) . '">' . $category->name . '</a>'; 扩展阅读get_cat_ID()函数位于:wp-includes/category.php …
WordPress函数get_category_by_slug根据分类的别名返回分类对象。 get_category_by_slug( string $slug ) 函数参数$slug 字符串 分类的别名,例如:develop 函数返回值WP_Term Object ( [term_id] => 1 [name] => 分类名称 [slug] => 分类别名 [term_group] => 0 [term_taxonomy_id] => 1 [taxonomy] => category [description] => 分类描述 [parent] => 0 [count] => 22 [filter] => raw [cat_ID] => 1 [category_count] => 22 [category_description] => 分类描述 [cat_name] => 分类名称 [category_nicename] => 分类别名 [category_parent] => 0 ) 函数使用示例$category = get_category_by_slug('develop'); echo '<a href="' . get_category_link($category->cat_ID) . '">' . $category->name . '</a>'; 扩展阅读get_category_by_slug()函数位于:wp-includes/category.php …
WordPress函数get_category_by_path可以根据分类的路径或别名获取分类对象。 get_category_by_path( string $category_path, bool $full_match=true, string $output=OBJECT ) 函数参数$category_path 字符串 包含分类别名的路径或者直接提供别名 …
WordPress函数get_category用于获取分类对象。 get_category( int|object $category, string $output=OBJECT, string $filter='raw' ) 函数参数$category 整数或对象 分类的ID或分类对象 $output 字符串,默认值:OBJECT 返回的数据类型,默认返回对象,可选值: …
上一篇文章详细介绍了WordPress默认用户角色权限,以及如何新增用户角色、添加权限等,参考WordPress用户角色权限详解 在实际开发中,很少需要对默认权限进行修改,通常是添加若干个角色,然后对这些角色赋于不同的权限。 …
WordPress默认5个用户角色,分别为:订阅者、贡献者、作者、编辑和管理员,每个角色拥有不同的后台控制权,我们可以自由添加新的角色或为已有角色分配不同的权限。 用户角色权限可以打印全局变量 $wp_roles 来查看所有用户的权限和等级。 …
WordPress函数get_categories用于获取分类的信息 get_categories( string|array $args = '' ) 函数参数$args数组或字符串,get_categories支持的参数与WP_Term_Query::__construct()相同。 …
WordPress函数get_all_category_ids以数组的形式返回所有分类的ID,在个性定制主题时非常有用,该函数没有任何参数。 get_all_category_ids() 函数返回值Array ( [0] => 6 [1] => 9 [2] => 7 [3] => 1 [4] => 4 [5] => 5 [6] => 8 ) 函数使用示例以下示例将输出所有分类的链接列表: …