Kalite Post Custom ak Kategori Custom

wordpress

WordPress is becoming such an indispensable platform to so many companies, but the average company doesn't even take advantage of a fraction of the capabilities. One of our clients wanted to add a resource section to their site but didn't want to do it using pages nor in blog posts. This is exactly what WordPress supports Kalite Post Custom pou!

In this case, we wanted to add a Resource Section to one of our clients' sites. It's fairly simple to add a Kalite Post Custom nan tèm WordPress ou. Ou ajoute kòd sa a lè l sèvi avèk fonksyon an register_post_type nan paj functions.php ou:

// Ajoute Resous Custom Post Kalite add_action ('init', 'create_post_type'); fonksyon create_post_type () {register_post_type ('resous', etalaj ('etikèt' => etalaj ('non' => __ ('Resous'), 'singular_name' => __ ('Resous'), 'add_new' => __ ('Add New'), 'add_new_item' => __ ('Add New Resource'), 'edit_item' => __ ('Edit Resource'), 'new_item' => __ ('New Resource'), 'all_items' => __ ('Tout Resous'), 'view_item' => __ ('Gade Resous'), 'search_items' => __ ('Rechèch Resous'), 'not_found' => __ ('Resous pa jwenn'), 'not_found_in_trash' => __ ('Pa gen resous nan fatra'), 'parent_item_colon' => '', 'menu_name' => __ ('Resous')), 'piblik' => vre, 'has_archive' => vre, 'Reyekri' => etalaj ('paresseux' => 'resous'), 'sipò' => etalaj ('tit', 'editè', 'otè', 'thumbnail', 'ekstrè', 'kòmantè'))) ; }

Yon ti kras pi difisil jwenn te ki jan fè kategori koutim pou ou Kalite Post Custom. One reason why it's difficult to figure out how to do this is because it's called a custom taxonomy and utilizes the register_taxonomy function to customize it. In this case, we're wanting to add resource types like Webinars, Whitepapers, etc. to the theme… so here's some additional code for the functions.php file:

add_action ('init', 'resource_category_init', 100); // 100 se konsa kalite pòs la te anrejistre fonksyon resource_category_init () {register_taxonomy ('kalite', 'resous', etalaj ('labels' => etalaj ('name' => 'Kalite Resous', 'singular_name' => ' Kalite Resous ',' search_items '=>' Rechèch Kalite Resous ',' popular_items '=>' Kalite Resous Popilè ',' all_items '=>' Tout Kalite Resous ',' edit_item '=> __ (' Edite Kalite Resous ') , 'update_item' => __ ('Mizajou Kalite Resous'), 'add_new_item' => __ ('Add Nouvo Kalite Resous'), 'new_item_name' => __ ('Nouvo Kalite Resous')), 'yerarchize' => 'fo', 'etikèt' => 'Kalite Resous')); }

Kalite Post Custom pèmèt ou tou konsepsyon achiv la ak paj sèl pou kalite Post Custom ou yo. Jis kopye dosye archive.php ak single.php. Chanje non kopi yo ak Kalite Post Custom nan non an. Nan ka sa a, ki ta dwe archive-resources.php ak sèl-resources.php. Koulye a, ou ka Customize paj sa yo sepandan ou vle paj la resous yo gade.

2 Kòmantè

  1. 1

    Yon lòt fason ta dwe sèvi ak yon Plugin tankou Fasil kalite kontni Custom oswa Kalite.

    Grefon sa yo tou pèmèt ou fasil ajoute bwat meta koutim ak kreye paj koutim ak afiche modèl.

    • 2

      Trè vre @ google-d5279c8b66d25549a0ec3c8dd46a3d1a: disqus! Mwen pral onèt ke mwen santi mwen tankou yon koup la grefon yo ajoute yon tòn anlè nan blog la ... epi ou pa ka jis deplase yon tèm soti nan yon sit nan pwochen an, ou dwe asire w ke ou deplase grefon yo, tou . Se sèl rezon mwen travay pou mete fonksyon ki nesesè yo nan dosye tèm yo.

Ki sa ou panse?

Sit sa a sèvi ak Akismet diminye Spam. Aprann kijan kòmantè ou a trete.