Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_action( 'init', 'testimonial' );
- function testimonial() {
- register_post_type( 'testimonials',
- array(
- 'labels' => array(
- 'name' => 'testimonials',
- 'singular_name' => 'testimonial',
- 'add_new' => 'Add New',
- 'add_new_item' => 'Add New testimonial',
- 'edit' => 'Edit',
- 'edit_item' => 'Edit testimonial',
- 'new_item' => 'New testimonial',
- 'view' => 'View',
- 'view_item' => 'View new testimonial',
- 'search_items' => 'Search testimonial',
- 'not_found' => 'No testimonials found',
- 'not_found_in_trash' => 'No testimonials in Trash',
- 'parent' => 'Parent testimonial'
- ),
- 'public' => true,
- 'menu_position' => 16,
- 'supports' => array( 'title', 'editor', 'comments', 'thumbnail' ),
- 'taxonomies' => array( '' ),
- 'menu_icon' => true,
- 'has_archive' => true
- )
- );
- }
- //nampilin customnya
- add_action( 'admin_init', 'testi' );
- function testi() {
- add_meta_box( 'testimonial_meta_box',
- 'testimonials Details',
- 'display_testimonial_name_meta_box',
- 'testimonials', 'normal', 'high'
- );
- }
- //formnya
- function display_testimonial_name_meta_box( $testimonial ) {
- // Ambil harga
- $testimonial_name = esc_html( get_post_meta( $testimonial->ID, 'testimonial_name', true ) );
- echo "<table>
- <tr>
- <td style='width: 100%'>Nama</td>
- <td><input type='text' size='80' name='post_testimonial_name' value='". $testimonial_name."' /></td>
- </tr>
- </table>";
- }
- //custom field ke database
- add_action( 'save_post', 'add_testimonial_name_fields', 10, 2 );
- //This function is executed when posts are saved or deleted from the admin panel
- function add_testimonial_name_fields( $testimonial_id, $testimonial ) {
- // Check post type for post stuffs
- if ( $testimonial->post_type == 'testimonials' ) {
- // Store data in post meta table if present in post data
- if ( isset( $_POST['testimonial_name'] ) && $_POST['testimonial_name'] != '' ) {
- update_post_meta( $testimonial_id, 'testimonial_name', $_POST['testimonial_name'] );
- }
- }
- }
- //buat single post untuk ini
- add_filter( 'template_include', 'laman_testi', 1 );
- function laman_testi( $template_path ) {
- if ( get_post_type() == 'testimonials' ) {
- if ( is_single() ) {
- // checks if the file exists in the theme first,
- // otherwise serve the file from the plugin
- if ( $theme_file = locate_template( array ( 'single-testimonial.php' ) ) ) {
- $template_path = $theme_file;
- } else {
- $template_path = plugin_dir_path( __FILE__ ) . '/single-testimonial.php';
- }
- }
- }
- return $template_path;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement