Jenis Pasangan Khusus sareng Kategori Khusus

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 Jenis Tulisan Adat pikeun!

In this case, we wanted to add a Resource Section to one of our clients' sites. It's fairly simple to add a Custom Tulisan Tipe kana téma WordPress anjeun. Anjeun nambihan kode ieu nganggo fungsina register_post_type ka halaman functions.php anjeun:

// Add Resources Custom Post Type add_action ('init', 'create_post_type'); function 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' => __ ('All Resources'), 'view_item' => __ ('View Resource'), 'search_items' => __ ('Search Resources'), 'not_found' => __ ('Resource Not Found'), 'not_found_in_trash' => __ ('No Resources in Trash'), 'parent_item_colon' => '', 'menu_name' => __ ('Resources')), 'public' => true, 'has_archive' => leres, 'rewrite' => susunan ('slug' => 'sumberdaya'), 'ngadukung' => susunan ('judul', 'éditor', 'panulis', 'gambar leutik', 'excerpt', 'koméntar')) ; }

Sakedik langkung sesah milari kumaha cara ngadamelna kategori custom keur anjeun Custom Tulisan Tipe. 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 janten jinis tulisan parantos didaptarkeun fungsi resource_category_init () {register_taxonomy ('type', 'resources', array ('labels' => array ('name' => 'Resource Type', 'singular_name' => ' Tipe Sumberdaya ',' search_items '=>' Tipe Sumber Daya Milarian ',' popular_items '=>' Jenis Sumber Daya Anu Populer ',' all_items '=>' Sadayana Jenis Sumber Daya ',' edit_item '=> __ (' Édit Tipe Sumber Daya ') , 'update_item' => __ ('Update Type Resource'), 'add_new_item' => __ ('Add New Resource Type'), 'new_item_name' => __ ('New Resource Type')), 'hierarchical' => 'false', 'label' => 'Type Resource')); }

Jinis Pos Khusus ogé ngamungkinkeun anjeun mendesain arsip sareng halaman hiji pikeun Jinis Pos Khusus anjeun. Ngan nyalin arsip.php sareng file single.php. Ganti ngaran salinan na Custom Tulisan Tipe dina nami. Dina hal ieu, éta bakal janten arsip-resources.php sareng single-resources.php. Ayeuna anjeun tiasa ngaropea halaman-halaman éta tapi anjeun hoyong halaman sumber pikeun ditingali.

2 Komentar

  1. 1

    Cara sanésna nyaéta ngagunakeun plugin sapertos Jinis Kandungan Adat Gampang atanapi Jenis.

    Plugins ieu ogé ngamungkinkeun anjeun pikeun gampang nambihan kotak meta khusus sareng nyiptakeun halaman khusus sareng pasang témplat.

    • 2

      Leres pisan @ google-d5279c8b66d25549a0ec3c8dd46a3d1a: disqus! Kuring bakal jujur ​​yén kuring siga sababaraha plugins nambihan seueur overhead kana blog ... sareng anjeun henteu tiasa mindahkeun téma tina hiji situs ka situs anu sanésna, anjeun kedah pastikeun anjeun mindahkeun plugins ogé . Éta hiji-hijina alesan kuring damel pikeun ngalebetkeun fungsi anu diperyogikeun dina file téma.

Naon anu anjeun pikirkeun?

Situs migunakeun Akismet pikeun ngurangan spam. Diajar kumaha komentar data anjeun diolah.