Advertisement
Guest User

Untitled

a guest
Aug 19th, 2013
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.25 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: Rotating Testimonials
  4. Version: 0.1
  5. Plugin URI: http://www.wpbeginner.com/
  6. Description: Rotating Testimonials is a plugin that lets you add rotating testimonials in WordPress
  7. Author: WPBeginner
  8. Author URI: http://www.wpbeginner.com/
  9. */
  10.  
  11. add_action( 'init', 'wpb_register_cpt_testimonial' );
  12.  
  13. function wpb_register_cpt_testimonial() {
  14.  
  15.     $labels = array(
  16.         'name' => _x( 'Case Studies', 'casestudy' ),
  17.         'singular_name' => _x( 'testimonial', 'casestudy' ),
  18.         'add_new' => _x( 'Add New', 'casestudy' ),
  19.         'add_new_item' => _x( 'Add New case study', 'casestudy' ),
  20.         'edit_item' => _x( 'Edit case study', 'casestudy' ),
  21.         'new_item' => _x( 'New case study', 'casestudy' ),
  22.         'view_item' => _x( 'View case study', 'casestudy' ),
  23.         'search_items' => _x( 'Search case studies', 'casestudy' ),
  24.         'not_found' => _x( 'No case studies found', 'casestudy' ),
  25.         'not_found_in_trash' => _x( 'No case studies found in Trash', 'casestudy' ),
  26.         'parent_item_colon' => _x( 'Parent case study:', 'casestudy' ),
  27.         'menu_name' => _x( 'Case Studies', 'casestudy' ),
  28.     );
  29.  
  30.     $args = array(
  31.         'labels' => $labels,
  32.         'hierarchical' => false,
  33.         'taxonomies' => array('category'),
  34.         'supports' => array( 'title', 'thumbnail', 'revisions' ),
  35.         'public' => true,
  36.         'show_ui' => true,
  37.         'show_in_menu' => true,
  38.         'show_in_nav_menus' => true,
  39.         'publicly_queryable' => true,
  40.         'exclude_from_search' => false,
  41.         'has_archive' => true,
  42.         'query_var' => true,
  43.         'can_export' => true,
  44.         'rewrite' => true,
  45.         'capability_type' => 'post'
  46.        
  47.     );
  48.  
  49.     register_post_type( 'casestudy', $args );
  50. }
  51.  
  52.         $key = "casestudy";
  53.         $meta_boxes = array(
  54.         "the-problem" => array(
  55.         "name" => "the-problem",
  56.         "title" => "The Problem",
  57.         "description" => "Add the problem text"),
  58.        
  59.         "what-we-did" => array(
  60.         "name" => "what-we-did",
  61.         "title" => "What We Did",
  62.         "description" => "Add the what we did text"),
  63.        
  64.         "the-outcome" => array(
  65.         "name" => "the-outcome",
  66.         "title" => "The Outcome",
  67.         "description" => "Add the outcome text"),
  68.        
  69.         );
  70.  
  71. function wpb_create_meta_box() {
  72. global $key;
  73.  
  74. if( function_exists( 'add_meta_box' ) ) {
  75. add_meta_box( 'new-meta-boxes', ucfirst( $key ) . ' Information', 'display_meta_box', 'casestudy', 'normal', 'high' );
  76. }
  77. }
  78.  
  79. function display_meta_box() {
  80. global $post, $meta_boxes, $key;
  81. ?>
  82.  
  83. <div class="form-wrap">
  84.  
  85. <?php
  86. wp_nonce_field( plugin_basename( __FILE__ ), $key . '_wpnonce', false, true );
  87.  
  88. foreach($meta_boxes as $meta_box) {
  89. $data = get_post_meta($post->ID, $key, true);
  90. ?>
  91.  
  92. <div class="form-field form-required">
  93. <label for="<?php echo $meta_box[ 'name' ]; ?>"><?php echo $meta_box[ 'title' ]; ?></label>
  94. <input type="text" name="<?php echo $meta_box[ 'name' ]; ?>" value="<?php echo htmlspecialchars( $data[ $meta_box[ 'name' ] ] ); ?>" />
  95. <p><?php echo $meta_box[ 'description' ]; ?></p>
  96. </div>
  97.  
  98. <?php } ?>
  99.  
  100. </div>
  101. <?php
  102. }
  103.  
  104. function wpb_save_meta_box( $post_id ) {
  105. global $post, $meta_boxes, $key;
  106.  
  107. foreach( $meta_boxes as $meta_box ) {
  108. $data[ $meta_box[ 'name' ] ] = $_POST[ $meta_box[ 'name' ] ];
  109. }
  110.  
  111. if ( !wp_verify_nonce( $_POST[ $key . '_wpnonce' ], plugin_basename(__FILE__) ) )
  112. return $post_id;
  113.  
  114. if ( !current_user_can( 'edit_post', $post_id ))
  115. return $post_id;
  116.  
  117. update_post_meta( $post_id, $key, $data );
  118. }
  119.  
  120. add_action( 'admin_menu', 'wpb_create_meta_box' );
  121. add_action( 'save_post', 'wpb_save_meta_box' );
  122.  
  123.  
  124.  
  125. function wpb_display_testimonials() { ?>
  126.  
  127.  
  128. <div id="testimonials">
  129. <?php
  130. $args = array( 'post_type' => 'casestudy', 'posts_per_page' => 3, 'orderby' => 'menu_order', 'order' => 'ASC' );
  131. $loop = new WP_Query( $args );
  132. if ( $loop->have_posts() ) : while ( $loop->have_posts() ) : $loop->the_post();
  133. $data = get_post_meta( $loop->post->ID, 'casestudy', true );
  134. static $count = 0;
  135. if ($count == "1") { ?>
  136.  
  137. <div class="slide">
  138.     <div id="kirin_case_study_w-2" class="widget widget_kirin_case_study_w">
  139.         <h3 class="widget-title">Case Study</h3>
  140.             <div class="control-links"></div>
  141.         <div class="case-thumbnail">
  142.             <?php if (has_post_thumbnail() ) {  the_post_thumbnail('case-study-image'); ?></a>
  143.            
  144.             <?php } else { ?>
  145.            
  146.             <img src="<?php bloginfo('template_directory'); ?>/images/case-study.jpg" alt="<?php the_title(); ?>" />
  147.                                    
  148.             <?php } ?>        
  149.         </div><!-- .case-thumbnail -->
  150.         <div class="case-study">
  151.             <h4>The Problem</h4>
  152.                 <p><?php echo $data[ 'the-problem' ]; ?></p>               
  153.             <h4>What We Did</h4>
  154.                 <p><?php echo $data[ 'what-we-did' ]; ?></p>
  155.             <h4 class="orange">The Outcome</h4>
  156.                 <p><?php echo $data[ 'the-outcome' ]; ?></p>
  157.             <p class="readmore"><a href="http://techpundits.co.uk/ki-rin/case-studies">more</a></p>
  158.         </div><!-- .case-study -->
  159.     </div><!-- .widget_kirin_case_study_w -->
  160. </div><!-- .slide -->
  161.  
  162.  
  163. <?php }
  164. else { ?>
  165.  
  166. <div class="slide">
  167.     <div id="kirin_case_study_w-2" class="widget widget_kirin_case_study_w">
  168.         <h3 class="widget-title">Case Study</h3>
  169.             <div class="control-links"></div>
  170.         <div class="case-thumbnail">
  171.             <?php if (has_post_thumbnail() ) {  the_post_thumbnail('case-study-image'); ?></a>
  172.            
  173.             <?php } else { ?>
  174.            
  175.             <img src="<?php bloginfo('template_directory'); ?>/images/case-study.jpg" alt="<?php the_title(); ?>" />
  176.                                    
  177.             <?php } ?>  
  178.         </div><!-- .case-thumbnail -->
  179.         <div class="case-study">
  180.             <h4>The Problem</h4>
  181.                 <p><?php echo $data[ 'the-problem' ]; ?></p>               
  182.             <h4>What We Did</h4>
  183.                 <p><?php echo $data[ 'what-we-did' ]; ?></p>
  184.             <h4 class="orange">The Outcome</h4>
  185.                 <p><?php echo $data[ 'the-outcome' ]; ?></p>
  186.             <p class="readmore"><a href="http://techpundits.co.uk/ki-rin/case-studies">more</a></p>
  187.         </div><!-- .case-study -->
  188.     </div><!-- .widget_kirin_case_study_w -->
  189. </div><!-- .slide -->
  190.  
  191.  
  192. <?php
  193. $count++; }
  194. endwhile;
  195. endif;
  196. echo '</div>';
  197. }
  198. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement