內容營銷

具有自定義類別的自定義帖子類型

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 是 CMO 的 開放洞察 和創始人 Martech Zone。 道格拉斯幫助了數十家成功的 MarTech 新創公司,協助進行了超過 5 億美元的 MarTech 收購和投資盡職調查,並繼續協助公司實施和自動化其銷售和行銷策略。 道格拉斯是國際公認的數位轉型和 MarTech 專家和演講者。 道格拉斯也是一本傻瓜指南和一本商業領導書的出版作者。

相關文章

返回頂部按鈕
關閉

檢測到Adblock

Martech Zone 我們能夠免費為您提供這些內容,因為我們通過廣告收入、聯屬鏈接和讚助從我們的網站中獲利。 如果您在瀏覽我們的網站時刪除廣告攔截器,我們將不勝感激。