内容营销

具有自定义类别的自定义帖子类型

WordPress已成为许多公司不可或缺的平台,但是普通公司甚至没有利用其中的一部分功能。 我们的一位客户希望在其网站上添加资源部分,但不希望使用页面或博客文章来添加。 这正是WordPress支持的 自定义文章类型 对于!

在这种情况下,我们希望将资源部分添加到客户的站点之一。 添加一个很简单 Custom Post Type 到您的WordPress主题。 您使用函数添加以下代码 register_post_type 到您的functions.php页面:

//添加资源自定义帖子类型add_action('init','create_post_type'); 函数create_post_type(){register_post_type('resources',array('labels'=> array('name'=> __('Resources'),'singular_name'=> __('Resource'),'add_new'=> __ ('Add New'),'add_new_item'=> __('Add New Resource'),'edit_item'=> __('Edit Resource'),'new_item'=> __('New Resource'),'all_items' => __('所有资源'),'view_item'=> __('View Resource'),'search_items'=> __('Search Resources'),'not_found'=> __('Resource Not Found'), 'not_found_in_trash'=> __('垃圾桶中没有资源'),'parent_item_colon'=>'','menu_name'=> __('Resources')),'public'=> true,'has_archive'=> true, 'rewrite'=> array('slug'=>'resources'),'supports'=> array('title','editor','author','thumbnail','excerpt','comments')))) ; }

很难找到的是如何制作 自定义类别 关于 Custom Post Type。 之所以很难做到这一点,是因为它被称为自定义分类法,并且利用了

注册分类法 功能来定制它。 在这种情况下,我们想要向主题中添加网络研讨会、白皮书等资源类型……所以这里是 functions.php 文件的一些附加代码:

add_action('init','resource_category_init',100); // 100,因此已注册帖子类型function resource_category_init(){register_taxonomy('type','resources',array('labels'=> array('name'=>'Resource Type','singular_name'=>'资源类型'','search_items'=>'搜索资源类型','popular_items'=>'流行资源类型','all_items'=>'所有资源类型','edit_item'=> __('Edit Resource Type') ,'update_item'=> __('Update Resource Type'),'add_new_item'=> __('Add New Resource Type'),'new_item_name'=> __('New Resource Type')),'hierarchical'=> 'false','label'=>'资源类型')); }

自定义帖子类型还允许您设计自定义帖子类型的档案和单个页面。 只需复制archive.php和single.php文件。 将副本重命名为 Custom Post Type 在名字里。 在这种情况下,它将是archive-resources.php和single-resources.php。 现在,您可以自定义这些页面,但是希望资源页面显示出来。

Douglas Karr

Douglas Karr 首席营销官是 开放洞察 和创始人 Martech Zone。 道格拉斯帮助了数十家成功的 MarTech 初创公司,协助进行了超过 5 亿美元的 MarTech 收购和投资尽职调查,并继续协助公司实施和自动化其销售和营销策略。 道格拉斯是国际公认的数字化转型和 MarTech 专家和演讲者。 道格拉斯还是一本傻瓜指南和一本商业领导力书籍的出版作者。

相关文章

返回顶部按钮
关闭

检测到Adblock

Martech Zone 我们能够免费为您提供这些内容,因为我们通过广告收入、联属链接和赞助从我们的网站中获利。 如果您在浏览我们的网站时删除广告拦截器,我们将不胜感激。