Advertisement
Tycoon_Hosting

AppThemes Rotating Client Testimonials Plugin/Add-on

Nov 22nd, 2012
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 9.89 KB | None | 0 0
  1. In this tutorial we will cover everything needed to create your own testimonials area for the AppThemes JobRoller, ClassiPress and Vantage themes.
  2.  
  3. Screenshots:
  4. http://postimage.org/image/nkn3v5a2j/
  5. http://postimage.org/image/c4iflh3gf/
  6.  
  7. STEP 1: PASTE THE FOLLOWING INTO YOUR CHILD-THEME'S FUNCTION.PHP FILE.
  8.  
  9. /*-- Begin: Rotating Testimonials Post Type--*/
  10. function jr_testimonial_post_type() { register_post_type( 'jr_testimonial',
  11. array( 'labels' => array(
  12. 'name' => __( 'Client Testimonials', 'appthemes' ),
  13. 'singular_name' => __( 'Testimonial', 'appthemes' ),
  14. 'add_new' => __( 'Add New', 'appthemes' ),
  15. 'add_new_item' => __( 'Add New Testimonial', 'appthemes' ),
  16. 'edit_item' => __( 'Edit Testimonial', 'appthemes' ),
  17. 'new_item' => __( 'New Testimonial', 'appthemes' ),
  18. 'view_item' => __( 'View Testimonials', 'appthemes' ),
  19. 'search_items' => __( 'Search Testimonials', 'appthemes' ),
  20. 'not_found' => __( 'Sorry, No Testimonials found', 'appthemes' ),
  21. 'not_found_in_trash' => __( 'No Testimonials found in the Trash', 'appthemes' ),
  22. 'parent_item_colon' => __( 'Parent Testimonial:', 'appthemes' ),
  23. 'menu_name' => __( 'Testimonials', 'appthemes' ),
  24. ),
  25.  
  26. 'singular_label' => __('Testimonials', 'appthemes'),
  27. 'hierarchical' => false,
  28. 'public' => true,
  29. 'show_ui' => true,
  30. 'show_in_menu' => true,
  31. 'menu_position' => 10,
  32. 'show_in_nav_menus' => true,
  33. 'publicly_queryable' => true,
  34. 'exclude_from_search' => false,
  35. '_builtin' => false,
  36. '_edit_link' => 'post.php?post=%d',
  37. 'has_archive' => true,
  38. 'query_var' => true,
  39. 'can_export' => true,
  40. 'rewrite' => array('slug' => 'testimonials'),
  41. 'capability_type' => 'post',
  42. 'supports' => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'custom-fields', 'revisions' ),
  43. 'register_meta_box_cb' => 'add_testimonials_metaboxes'
  44. ) ); }
  45.  
  46. add_action( 'init', 'jr_testimonial_post_type' );
  47.  
  48. function jr_testimonial_post_type_header() { global $post_type; ?> <style>
  49. <?php if (($_GET['post_type'] == 'jr_testimonial') || ($post_type == 'jr_testimonial')) : ?>
  50. #icon-edit { background:transparent url('<?php bloginfo('stylesheet_directory'); ?>/images/testimonial-icon-big.png') no-repeat 0 0; }
  51. <?php endif; ?>
  52. #adminmenu #menu-posts-jr_testimonial div.wp-menu-image{background:transparent url('<?php bloginfo('stylesheet_directory'); ?>/images/testimonial-icon.png') no-repeat scroll 6px -30px;}
  53. #adminmenu menu-posts-jr_testimonial:hover div.wp-menu-image,#adminmenu #menu-posts-jr_testimonial.wp-has-current-submenu div.wp-menu-image{background:transparent url('<?php bloginfo('stylesheet_directory'); ?>/images/testimonial-icon.png') no-repeat scroll 6px 5px;}        
  54. </style> <?php }
  55.  
  56. add_action('admin_head', 'jr_testimonial_post_type_header');
  57.  
  58. // Add the Testimonials Meta Boxes
  59. function add_testimonials_metaboxes() {
  60. add_meta_box('jr_testimonial_meta_box', __('Testimonial Information', 'appthemes'), 'jr_testimonial_meta_box', 'jr_testimonial', 'side', 'high');
  61. }
  62. add_action( 'add_meta_boxes', 'add_testimonials_metaboxes' );
  63.  
  64. // The Testimonials Metabox
  65. function jr_testimonial_meta_box() { global $post;
  66.  
  67. // Noncename needed to verify where the data originated from
  68. echo '<input type="hidden" name="jr_testimonial_meta_noncename" id="jr_testimonial_meta_noncename" value="' .wp_create_nonce( plugin_basename(__FILE__) ) . '" />';
  69.  
  70. // Echo out the field and data if it's already been entered
  71. $name = get_post_meta($post->ID, '_client_name', true);
  72. echo __('<p><strong>Client\'s Name</strong><br/>', 'appthemes');
  73. echo __('<em>Enter the name of the person who gave you the testimonial.</em></p>', 'appthemes');
  74. echo '<input type="text" name="_client_name" value="' . $name  . '" class="widefat" />';
  75.  
  76. $position = get_post_meta($post->ID, '_company_position', true);
  77. echo __('<p><strong>Position in Company</strong><br/>', 'appthemes');
  78. echo __('<em>Enter their position in their specific company.</em></p>', 'appthemes');
  79. echo '<input type="text" name="_company_position" value="' . $position  . '" class="widefat" />';
  80.  
  81. $company = get_post_meta($post->ID, '_company_name', true);
  82. echo __('<p><strong>Company Name</strong><br/>', 'appthemes');
  83. echo __('<em>Enter the client Company Name.</em></p>', 'appthemes');
  84. echo '<input type="text" name="_company_name" value="' . $company  . '" class="widefat" />';
  85.  
  86. $link = get_post_meta($post->ID, '_client_link', true);
  87. echo __('<p><strong>Client Link</strong><br/>', 'appthemes');
  88. echo __('<em>Enter the link to client\'s site, or you can enter the link to your portfolio page where you have the client displayed.</em></p>', 'appthemes');
  89. echo '<input type="text" name="_client_link" value="' . $link  . '" class="widefat" />';
  90.  
  91. }
  92.  
  93. // Save the Testimonial Metabox Data
  94. function jr_save_testimonial_meta($post_id, $post) {
  95. if ( !wp_verify_nonce( $_POST['jr_testimonial_meta_noncename'], plugin_basename(__FILE__) )) { return $post->ID; }
  96. if ( !current_user_can( 'edit_post', $post->ID )) return $post->ID;
  97.  
  98. $testimonial_meta['_client_name'] = $_POST['_client_name'];
  99. $testimonial_meta['_company_position'] = $_POST['_company_position'];  
  100. $testimonial_meta['_company_name'] = $_POST['_company_name'];
  101. $testimonial_meta['_client_link'] = $_POST['_client_link'];
  102.  
  103. // Add values of $testimonial_meta as custom fields
  104. foreach ($testimonial_meta as $key => $value) {
  105. // Cycle through the $testimonial_meta array!
  106. if( $post->post_type == 'revision' ) return;
  107. // Don't store our data twice
  108. $value = implode(',', (array)$value);
  109. // If $value is an array, make it a CSV (unlikely)
  110. if(get_post_meta($post->ID, $key, FALSE)) {
  111. // If the custom field already has a value
  112. update_post_meta($post->ID, $key, $value);
  113. } else {
  114. // If the custom field doesn't have a value
  115. add_post_meta($post->ID, $key, $value);
  116. }
  117. if(!$value) delete_post_meta($post->ID, $key);
  118. // Delete if blank
  119. } }
  120. add_action('save_post', 'jr_save_testimonial_meta', 1, 2);
  121.  
  122.  
  123. // Change the columns for the edit Testimonial Screen
  124. function jr_testimonial_change_columns( $cols ) {
  125.  
  126. $cols = array(
  127. 'cb'       => '<input type="checkbox" />',
  128. 'title'    => __('Title', 'appthemes' ),
  129. 'client'   => __('Client\'s Name', 'appthemes'),
  130. 'position' => __('Company Position', 'appthemes'),
  131. 'company'  => __('Company Name', 'appthemes'),
  132. 'link'     => __('Client Link', 'appthemes' ),
  133. ); return $cols; }
  134.  
  135. add_filter( "manage_jr_testimonial_posts_columns", "jr_testimonial_change_columns" );
  136.  
  137. // Now let’s fill these new columns with some content from the custom post type:
  138. function jr_testimonial_columns( $column, $post_id ) { switch ( $column ) {
  139. case "client": echo get_post_meta( $post_id, '_client_name', true); break;
  140. case "position": echo get_post_meta( $post_id, '_company_position', true); break;
  141. case "company": echo get_post_meta( $post_id, '_company_name', true); break;
  142. case "link": $link = get_post_meta( $post_id, '_client_link', true);
  143. echo '<a href="' . $link . '">' . $link. '</a>'; break;
  144. } }
  145.  
  146. add_action( "manage_posts_custom_column", "jr_testimonial_columns", 10, 2 );
  147.  
  148. // Make these columns sortable
  149. function jr_testimonial_sortable_columns() {
  150. return array('title' => 'title','client' => 'client','position' => 'position','company' => 'company','link' => 'link');
  151. }
  152. add_filter( "manage_edit-jr_testimonial_sortable_columns", "jr_testimonial_sortable_columns" );
  153.  
  154. // Add a Custom Post Type to a feed
  155. function add_jr_testimonial_to_feed( $qv ) {
  156. if ( isset($qv['feed']) && !isset($qv['post_type']) ) $qv['post_type'] = array('post', 'jr_testimonial'); return $qv;
  157. }
  158.  
  159. add_filter( 'request', 'add_jr_testimonial_to_feed' );
  160.  
  161. /*-- End: Rotating Testimonials Post Type --*/
  162.  
  163.  
  164. STEP 2: CREATE NEW PHP FILE INSIDE YOUR /INCLUDES/ FOLDER OF THE CHILD-THEME AND NAME IT TESTIMONIALS.PHP
  165.  
  166. :: Copy & Paste the Following ::
  167.  
  168. <div id="testimonials">
  169. <?php
  170. $args = array( 'post_type' => 'jr_testimonial', 'posts_per_page' => 10, 'orderby' => 'menu_order', 'order' => 'ASC' );
  171. $loop = new WP_Query( $args ); if ( $loop->have_posts() ) : while ( $loop->have_posts() ) : $loop->the_post();
  172. static $count = 0; if ($count == "1") { ?>
  173.  
  174. <div class="slide" style="display: none;">
  175. <div class="client-contact-info">
  176. <?php echo get_post_meta($post->ID, '_client_name', true); ?>,&nbsp;
  177. <?php echo get_post_meta($post->ID, '_company_position', true); ?>,&nbsp;
  178. <a href="<?php echo get_post_meta($post->ID, '_client_link', true); ?>" title="<?php echo get_post_meta($post->ID, '_company_name', true); ?>"><?php echo get_post_meta($post->ID, '_company_name', true); ?></a>
  179. </div>
  180.  
  181. <div class="clear"></div>
  182. <div class="testimonial-quote"><?php the_content(); ?></div>
  183. </div>
  184. <?php } else { ?>
  185.  
  186. <div class="slide">
  187. <div class="client-contact-info"><?php echo get_post_meta($post->ID, '_client_name', true); ?>,&nbsp;<?php echo get_post_meta($post->ID, '_company_position', true); ?>,&nbsp;<a href="<?php echo get_post_meta($post->ID, '_client_link', true); ?>" title="<?php echo get_post_meta($post->ID, '_company_name', true); ?>"><?php echo get_post_meta($post->ID, '_company_name', true); ?></a></div>
  188. <div class="clear"></div>
  189. <div class="testimonial-quote"><?php the_content(); ?></div>
  190. </div>
  191.  
  192. <?php $count++; } endwhile; endif; echo '</div>'; ?>
  193.  
  194.  
  195. <script type="text/javascript">
  196. /* <![CDATA[ */
  197.  
  198. jQuery(document).ready(function(){ jQuery('#testimonials .slide'); setInterval(function(){
  199. jQuery('#testimonials .slide').filter(':visible').fadeOut(1000,function(){ if(jQuery(this).next('.slide').size())
  200. { jQuery(this).next().fadeIn(1000); } else { jQuery('#testimonials .slide').eq(0).fadeIn(1000); } }); },10000); });
  201.  
  202. /* ]]> */
  203. </script>
  204.  
  205.  
  206. STEP 3: ADD THE FOLLOWING WHERE YOU WOULD LIKE TO HAVE TESTIMONIALS DISPLAYED, AND ADD STYLE TO IT VIA CSS
  207.  
  208. <!-- Begin: Testimonials Panel -->
  209. <?php get_template_part( 'includes/testimonials' ); ?>
  210. <!-- Begin: Testimonials Panel -->
  211.  
  212. ################ JUST LIKE THAT, YOU'RE DONE ################
  213.  
  214. Icons to add to your child themes /images/ folder:
  215.  
  216. http://postimage.org/image/ke9gwzx8t/
  217. http://postimage.org/image/x6xkwx8ul/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement