|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * Create Testimonial post type. |
| 5 | + * |
| 6 | + * To add custom fields use ACF plugin. |
| 7 | + * field names: rating; |
| 8 | + */ |
| 9 | +function ast_testimonial_post_type() |
| 10 | +{ |
| 11 | + |
| 12 | + $labels = array( |
| 13 | + 'name' => __( 'Testimonial', 'astra-child-theme' ), |
| 14 | + 'singular_name' => __( 'Testimonial', 'astra-child-theme' ), |
| 15 | + 'all_items' => __( 'All testimonials', 'astra-child-theme' ), |
| 16 | + 'add_new' => __( 'Add New', 'astra-child-theme' ), |
| 17 | + 'add_new_item' => __( 'Add new testimonial', 'astra-child-theme' ), |
| 18 | + 'edit_item' => __( 'Edit testimonial', 'astra-child-theme' ), |
| 19 | + 'new_item' => __( 'New testimonial', 'astra-child-theme' ), |
| 20 | + 'view_item' => __( 'View testimonial', 'astra-child-theme' ), |
| 21 | + 'search_items' => __( 'Search testimonial', 'astra-child-theme' ), |
| 22 | + 'not_found' => __( 'No testimonial found', 'astra-child-theme' ), |
| 23 | + 'not_found_in_trash' => __( 'No testimonial found in Trash', 'astra-child-theme' ), |
| 24 | + 'featured_image' => __( 'Testimonial Cover Photo','astra-child-theme' ), |
| 25 | + 'set_featured_image' => __('Set as testimonial\'s Cover picture','astra-child-theme'), |
| 26 | + ); |
| 27 | + |
| 28 | + $args = array( |
| 29 | + 'numberposts' => 15, |
| 30 | + 'labels' => $labels, |
| 31 | + 'menu_icon' => 'dashicons-format-quote', |
| 32 | + 'show_in_menu' => true, |
| 33 | + 'show_ui' => true, |
| 34 | + 'show_in_nav_menus' => true, |
| 35 | + 'public' => true, |
| 36 | + 'publicly_queryable' => true, |
| 37 | + 'has_archive' => true, |
| 38 | + 'rewrite' => array( 'slug' => 'testimonial', 'with_front' => false ), |
| 39 | + 'supports' => array( 'title', 'editor', 'thumbnail' ), |
| 40 | + ); |
| 41 | + |
| 42 | + register_post_type( 'testimonial', $args ); |
| 43 | + |
| 44 | +} |
| 45 | +add_action( 'init', 'ast_testimonial_post_type', 10, 1 ); |
| 46 | + |
| 47 | +/** |
| 48 | + * Edit columns |
| 49 | + * |
| 50 | + * @param array $columns |
| 51 | + * @return void |
| 52 | + */ |
| 53 | +function manage_testimonial_cols($columns) { |
| 54 | + |
| 55 | + $inserted = array( |
| 56 | + 'editor' => 'Testimonial', |
| 57 | + 'thumbnail' => 'Testimonial Photo', |
| 58 | + ); |
| 59 | + |
| 60 | + return array_merge( |
| 61 | + array_slice($columns, 0, 2), |
| 62 | + $inserted, |
| 63 | + array_slice($columns, 2) |
| 64 | + ); |
| 65 | +} |
| 66 | +add_filter( 'manage_testimonial_posts_columns', 'manage_testimonial_cols'); |
| 67 | + |
| 68 | +/** |
| 69 | + * Create Custom columns |
| 70 | + * |
| 71 | + * @param string $column_name |
| 72 | + * @param int $post_id |
| 73 | + * @return void |
| 74 | + */ |
| 75 | +function testimonial_field_col( $column_name, $post_id ){ |
| 76 | + |
| 77 | + if( $column_name == 'editor' ){ |
| 78 | + echo "Rating: ".get_field( 'rating' ); |
| 79 | + echo "<blockquote>\"".get_the_content()."\"</blockquote>"; |
| 80 | + } |
| 81 | + |
| 82 | + if( $column_name == 'thumbnail' ){ |
| 83 | + echo get_the_post_thumbnail( $post_id, 'thumbnail' ); |
| 84 | + } |
| 85 | + |
| 86 | +} |
| 87 | +add_action( 'manage_testimonial_posts_custom_column', 'testimonial_field_col', 10, 2); |
0 commit comments