Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1. Buat folder "product" di dalam folder template kita.
- 2. Buat file post-type.php dan masukkan dalam folder product di atas.
- 3. Panggil file tersebut dengan memasukkan kode berikut dalam file function.php:
- require get_template_directory() . '/products/post-type.php';
- 4. Masukkan kode berikut dalam file post-type.php:
- <?php
- function onphpid_post_type()
- {
- // add post-type
- register_post_type(
- 'onphpid_products',
- array(
- 'labels' => array(
- 'name' => __('Products', 'semi-toko-online'),
- 'singular_name' => __('Product', 'semi-toko-online'),
- 'add_new' => _x( 'Add New', 'product', 'semi-toko-online' ),
- 'add_new_item' => __( 'Add New Product', 'semi-toko-online' ),
- 'new_item' => __( 'New Product', 'twentytwelve' ),
- 'edit_item' => __( 'Edit Product', 'semi-toko-online' ),
- 'view_item' => __( 'View Product', 'semi-toko-online' ),
- 'all_items' => __( 'All Products', 'semi-toko-online' ),
- ),
- 'public' => true,
- 'supports' => array('title', 'editor', 'thumbnail'),
- 'has_archive' => true,
- 'rewrite' => array('slug'=>'product'),
- )
- );
- }
- add_action('init', 'onphpid_post_type');
- KETERANGAN:
- Setelah kalian menambahkan kode diatas kalian akan melihat menu Products di bawah menu Comments atau diatas menu Appearance.
- Pada tahap lanjutnya kita akan mengupah posisi dan icon agar sama dengan gambar pertama.
- Untuk mengubah posisi menu Custom Post Type kalian bisa menggunakan "menu_position" => 100, agar Menu berada dibawah Settings.
- Letakkan kode berikut di bawah "rewrite" => array("slug" => "product"),"
- ...
- 'public' => true,
- 'supports' => array('title', 'editor', 'thumbnail'),
- 'has_archive' => true,
- 'rewrite' => array('slug'=>'product'),
- 'menu_position' => 100, // code posisi
- ...
- 5. Jika kalian ingin menempatkan diposisi lain kalian bisa melihat list berikut:
- 5 – dibawah Posts
- 10 – dibawah Media
- 15 – dibawah Links
- 20 – dibawah Pages
- 25 – dibawah comments
- 60 – dibawah first separator
- 65 – dibawah Plugins
- 70 – dibawah Users
- 75 – dibawah Tools
- 80 – dibawah Settings
- 100 – dibawah second separator
- Kemudian kita akan mengganti icon Menu Custom Post Type. Kita bisa mengubah Icon kita dengan menggunakan ‘menu_icon’, caranya dengan menambahkan 'menu_icon' => 'dashicons-cart' untuk icon keranjang. Letakkan kode seperti dibawah
- ...
- 'public' => true,
- 'supports' => array('title', 'editor', 'thumbnail'),
- 'has_archive' => true,
- 'rewrite' => array('slug'=>'product'),
- 'menu_position' => 100,
- 'menu_icon' => 'dashicons-cart' // mengubah icon
- ...
- KETERANGAN:
- jika kalian ini mengganti dengan icon yang lain kalian bisa check di https://developer.wordpress.org/resource/dashicons/
- 6. Kurang Lebih Kode keseluruhan yang ada di post-type.php adalah sebagai berikut :
- <?php
- /**
- * tutorial membuat semi toko online
- * @package https://www.onphpid.com/category/membuat-semi-toko-online
- * @see : https://www.onphpid.com/langkah-awal-membuat-semi-toko-online-dengan-wordpress.html
- */
- function onphpid_post_type()
- {
- // add post-type
- register_post_type(
- 'onphpid_products',
- array(
- 'labels' => array(
- 'name' => __('Products', 'semi-toko-online'),
- 'singular_name' => __('Product', 'semi-toko-online'),
- 'add_new' => _x( 'Add New', 'product', 'semi-toko-online' ),
- 'add_new_item' => __( 'Add New Product', 'semi-toko-online' ),
- 'new_item' => __( 'New Product', 'semi-toko-online' ),
- 'edit_item' => __( 'Edit Product', 'semi-toko-online' ),
- 'view_item' => __( 'View Product', 'semi-toko-online' ),
- 'all_items' => __( 'All Products', 'semi-toko-online' ),
- ),
- 'public' => true,
- 'supports' => array('title', 'editor', 'thumbnail'),
- 'has_archive' => true,
- 'rewrite' => array('slug'=>'product'),
- 'menu_position' => 100,
- 'menu_icon' => 'dashicons-cart'
- )
- );
- }
- add_action('init', 'onphpid_post_type');
- KETERANGAN:
- Sekian dulu Tutorial Membuat Semi Toko Online Dengan WordPress. Selebihnya kalian bisa baca-baca di link berikut:
- https://codex.wordpress.org/Post_Types
- https://codex.wordpress.org/Function_Reference/register_post_type
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement