Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Plugin Name: Rotating Testimonials
- Version: 0.1
- Plugin URI: http://www.wpbeginner.com/
- Description: Rotating Testimonials is a plugin that lets you add rotating testimonials in WordPress
- Author: WPBeginner
- Author URI: http://www.wpbeginner.com/
- */
- add_action( 'init', 'wpb_register_cpt_testimonial' );
- function wpb_register_cpt_testimonial() {
- $labels = array(
- 'name' => _x( 'Case Studies', 'casestudy' ),
- 'singular_name' => _x( 'testimonial', 'casestudy' ),
- 'add_new' => _x( 'Add New', 'casestudy' ),
- 'add_new_item' => _x( 'Add New case study', 'casestudy' ),
- 'edit_item' => _x( 'Edit case study', 'casestudy' ),
- 'new_item' => _x( 'New case study', 'casestudy' ),
- 'view_item' => _x( 'View case study', 'casestudy' ),
- 'search_items' => _x( 'Search case studies', 'casestudy' ),
- 'not_found' => _x( 'No case studies found', 'casestudy' ),
- 'not_found_in_trash' => _x( 'No case studies found in Trash', 'casestudy' ),
- 'parent_item_colon' => _x( 'Parent case study:', 'casestudy' ),
- 'menu_name' => _x( 'Case Studies', 'casestudy' ),
- );
- $args = array(
- 'labels' => $labels,
- 'hierarchical' => false,
- 'taxonomies' => array('category'),
- 'supports' => array( 'title', 'thumbnail', 'revisions' ),
- 'public' => true,
- 'show_ui' => true,
- 'show_in_menu' => true,
- 'show_in_nav_menus' => true,
- 'publicly_queryable' => true,
- 'exclude_from_search' => false,
- 'has_archive' => true,
- 'query_var' => true,
- 'can_export' => true,
- 'rewrite' => true,
- 'capability_type' => 'post'
- );
- register_post_type( 'casestudy', $args );
- }
- $key = "casestudy";
- $meta_boxes = array(
- "the-problem" => array(
- "name" => "the-problem",
- "title" => "The Problem",
- "description" => "Add the problem text"),
- "what-we-did" => array(
- "name" => "what-we-did",
- "title" => "What We Did",
- "description" => "Add the what we did text"),
- "the-outcome" => array(
- "name" => "the-outcome",
- "title" => "The Outcome",
- "description" => "Add the outcome text"),
- );
- function wpb_create_meta_box() {
- global $key;
- if( function_exists( 'add_meta_box' ) ) {
- add_meta_box( 'new-meta-boxes', ucfirst( $key ) . ' Information', 'display_meta_box', 'casestudy', 'normal', 'high' );
- }
- }
- function display_meta_box() {
- global $post, $meta_boxes, $key;
- ?>
- <div class="form-wrap">
- <?php
- wp_nonce_field( plugin_basename( __FILE__ ), $key . '_wpnonce', false, true );
- foreach($meta_boxes as $meta_box) {
- $data = get_post_meta($post->ID, $key, true);
- ?>
- <div class="form-field form-required">
- <label for="<?php echo $meta_box[ 'name' ]; ?>"><?php echo $meta_box[ 'title' ]; ?></label>
- <input type="text" name="<?php echo $meta_box[ 'name' ]; ?>" value="<?php echo htmlspecialchars( $data[ $meta_box[ 'name' ] ] ); ?>" />
- <p><?php echo $meta_box[ 'description' ]; ?></p>
- </div>
- <?php } ?>
- </div>
- <?php
- }
- function wpb_save_meta_box( $post_id ) {
- global $post, $meta_boxes, $key;
- foreach( $meta_boxes as $meta_box ) {
- $data[ $meta_box[ 'name' ] ] = $_POST[ $meta_box[ 'name' ] ];
- }
- if ( !wp_verify_nonce( $_POST[ $key . '_wpnonce' ], plugin_basename(__FILE__) ) )
- return $post_id;
- if ( !current_user_can( 'edit_post', $post_id ))
- return $post_id;
- update_post_meta( $post_id, $key, $data );
- }
- add_action( 'admin_menu', 'wpb_create_meta_box' );
- add_action( 'save_post', 'wpb_save_meta_box' );
- function wpb_display_testimonials() { ?>
- <div id="testimonials">
- <?php
- $args = array( 'post_type' => 'casestudy', 'posts_per_page' => 3, 'orderby' => 'menu_order', 'order' => 'ASC' );
- $loop = new WP_Query( $args );
- if ( $loop->have_posts() ) : while ( $loop->have_posts() ) : $loop->the_post();
- $data = get_post_meta( $loop->post->ID, 'casestudy', true );
- static $count = 0;
- if ($count == "1") { ?>
- <div class="slide">
- <div id="kirin_case_study_w-2" class="widget widget_kirin_case_study_w">
- <h3 class="widget-title">Case Study</h3>
- <div class="control-links"></div>
- <div class="case-thumbnail">
- <?php if (has_post_thumbnail() ) { the_post_thumbnail('case-study-image'); ?></a>
- <?php } else { ?>
- <img src="<?php bloginfo('template_directory'); ?>/images/case-study.jpg" alt="<?php the_title(); ?>" />
- <?php } ?>
- </div><!-- .case-thumbnail -->
- <div class="case-study">
- <h4>The Problem</h4>
- <p><?php echo $data[ 'the-problem' ]; ?></p>
- <h4>What We Did</h4>
- <p><?php echo $data[ 'what-we-did' ]; ?></p>
- <h4 class="orange">The Outcome</h4>
- <p><?php echo $data[ 'the-outcome' ]; ?></p>
- <p class="readmore"><a href="http://techpundits.co.uk/ki-rin/case-studies">more</a></p>
- </div><!-- .case-study -->
- </div><!-- .widget_kirin_case_study_w -->
- </div><!-- .slide -->
- <?php }
- else { ?>
- <div class="slide">
- <div id="kirin_case_study_w-2" class="widget widget_kirin_case_study_w">
- <h3 class="widget-title">Case Study</h3>
- <div class="control-links"></div>
- <div class="case-thumbnail">
- <?php if (has_post_thumbnail() ) { the_post_thumbnail('case-study-image'); ?></a>
- <?php } else { ?>
- <img src="<?php bloginfo('template_directory'); ?>/images/case-study.jpg" alt="<?php the_title(); ?>" />
- <?php } ?>
- </div><!-- .case-thumbnail -->
- <div class="case-study">
- <h4>The Problem</h4>
- <p><?php echo $data[ 'the-problem' ]; ?></p>
- <h4>What We Did</h4>
- <p><?php echo $data[ 'what-we-did' ]; ?></p>
- <h4 class="orange">The Outcome</h4>
- <p><?php echo $data[ 'the-outcome' ]; ?></p>
- <p class="readmore"><a href="http://techpundits.co.uk/ki-rin/case-studies">more</a></p>
- </div><!-- .case-study -->
- </div><!-- .widget_kirin_case_study_w -->
- </div><!-- .slide -->
- <?php
- $count++; }
- endwhile;
- endif;
- echo '</div>';
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement