Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- In this tutorial we will cover everything needed to create your own testimonials area for the AppThemes JobRoller, ClassiPress and Vantage themes.
- Screenshots:
- http://postimage.org/image/nkn3v5a2j/
- http://postimage.org/image/c4iflh3gf/
- STEP 1: PASTE THE FOLLOWING INTO YOUR CHILD-THEME'S FUNCTION.PHP FILE.
- /*-- Begin: Rotating Testimonials Post Type--*/
- function jr_testimonial_post_type() { register_post_type( 'jr_testimonial',
- array( 'labels' => array(
- 'name' => __( 'Client Testimonials', 'appthemes' ),
- 'singular_name' => __( 'Testimonial', 'appthemes' ),
- 'add_new' => __( 'Add New', 'appthemes' ),
- 'add_new_item' => __( 'Add New Testimonial', 'appthemes' ),
- 'edit_item' => __( 'Edit Testimonial', 'appthemes' ),
- 'new_item' => __( 'New Testimonial', 'appthemes' ),
- 'view_item' => __( 'View Testimonials', 'appthemes' ),
- 'search_items' => __( 'Search Testimonials', 'appthemes' ),
- 'not_found' => __( 'Sorry, No Testimonials found', 'appthemes' ),
- 'not_found_in_trash' => __( 'No Testimonials found in the Trash', 'appthemes' ),
- 'parent_item_colon' => __( 'Parent Testimonial:', 'appthemes' ),
- 'menu_name' => __( 'Testimonials', 'appthemes' ),
- ),
- 'singular_label' => __('Testimonials', 'appthemes'),
- 'hierarchical' => false,
- 'public' => true,
- 'show_ui' => true,
- 'show_in_menu' => true,
- 'menu_position' => 10,
- 'show_in_nav_menus' => true,
- 'publicly_queryable' => true,
- 'exclude_from_search' => false,
- '_builtin' => false,
- '_edit_link' => 'post.php?post=%d',
- 'has_archive' => true,
- 'query_var' => true,
- 'can_export' => true,
- 'rewrite' => array('slug' => 'testimonials'),
- 'capability_type' => 'post',
- 'supports' => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'custom-fields', 'revisions' ),
- 'register_meta_box_cb' => 'add_testimonials_metaboxes'
- ) ); }
- add_action( 'init', 'jr_testimonial_post_type' );
- function jr_testimonial_post_type_header() { global $post_type; ?> <style>
- <?php if (($_GET['post_type'] == 'jr_testimonial') || ($post_type == 'jr_testimonial')) : ?>
- #icon-edit { background:transparent url('<?php bloginfo('stylesheet_directory'); ?>/images/testimonial-icon-big.png') no-repeat 0 0; }
- <?php endif; ?>
- #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;}
- #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;}
- </style> <?php }
- add_action('admin_head', 'jr_testimonial_post_type_header');
- // Add the Testimonials Meta Boxes
- function add_testimonials_metaboxes() {
- add_meta_box('jr_testimonial_meta_box', __('Testimonial Information', 'appthemes'), 'jr_testimonial_meta_box', 'jr_testimonial', 'side', 'high');
- }
- add_action( 'add_meta_boxes', 'add_testimonials_metaboxes' );
- // The Testimonials Metabox
- function jr_testimonial_meta_box() { global $post;
- // Noncename needed to verify where the data originated from
- echo '<input type="hidden" name="jr_testimonial_meta_noncename" id="jr_testimonial_meta_noncename" value="' .wp_create_nonce( plugin_basename(__FILE__) ) . '" />';
- // Echo out the field and data if it's already been entered
- $name = get_post_meta($post->ID, '_client_name', true);
- echo __('<p><strong>Client\'s Name</strong><br/>', 'appthemes');
- echo __('<em>Enter the name of the person who gave you the testimonial.</em></p>', 'appthemes');
- echo '<input type="text" name="_client_name" value="' . $name . '" class="widefat" />';
- $position = get_post_meta($post->ID, '_company_position', true);
- echo __('<p><strong>Position in Company</strong><br/>', 'appthemes');
- echo __('<em>Enter their position in their specific company.</em></p>', 'appthemes');
- echo '<input type="text" name="_company_position" value="' . $position . '" class="widefat" />';
- $company = get_post_meta($post->ID, '_company_name', true);
- echo __('<p><strong>Company Name</strong><br/>', 'appthemes');
- echo __('<em>Enter the client Company Name.</em></p>', 'appthemes');
- echo '<input type="text" name="_company_name" value="' . $company . '" class="widefat" />';
- $link = get_post_meta($post->ID, '_client_link', true);
- echo __('<p><strong>Client Link</strong><br/>', 'appthemes');
- 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');
- echo '<input type="text" name="_client_link" value="' . $link . '" class="widefat" />';
- }
- // Save the Testimonial Metabox Data
- function jr_save_testimonial_meta($post_id, $post) {
- if ( !wp_verify_nonce( $_POST['jr_testimonial_meta_noncename'], plugin_basename(__FILE__) )) { return $post->ID; }
- if ( !current_user_can( 'edit_post', $post->ID )) return $post->ID;
- $testimonial_meta['_client_name'] = $_POST['_client_name'];
- $testimonial_meta['_company_position'] = $_POST['_company_position'];
- $testimonial_meta['_company_name'] = $_POST['_company_name'];
- $testimonial_meta['_client_link'] = $_POST['_client_link'];
- // Add values of $testimonial_meta as custom fields
- foreach ($testimonial_meta as $key => $value) {
- // Cycle through the $testimonial_meta array!
- if( $post->post_type == 'revision' ) return;
- // Don't store our data twice
- $value = implode(',', (array)$value);
- // If $value is an array, make it a CSV (unlikely)
- if(get_post_meta($post->ID, $key, FALSE)) {
- // If the custom field already has a value
- update_post_meta($post->ID, $key, $value);
- } else {
- // If the custom field doesn't have a value
- add_post_meta($post->ID, $key, $value);
- }
- if(!$value) delete_post_meta($post->ID, $key);
- // Delete if blank
- } }
- add_action('save_post', 'jr_save_testimonial_meta', 1, 2);
- // Change the columns for the edit Testimonial Screen
- function jr_testimonial_change_columns( $cols ) {
- $cols = array(
- 'cb' => '<input type="checkbox" />',
- 'title' => __('Title', 'appthemes' ),
- 'client' => __('Client\'s Name', 'appthemes'),
- 'position' => __('Company Position', 'appthemes'),
- 'company' => __('Company Name', 'appthemes'),
- 'link' => __('Client Link', 'appthemes' ),
- ); return $cols; }
- add_filter( "manage_jr_testimonial_posts_columns", "jr_testimonial_change_columns" );
- // Now letβs fill these new columns with some content from the custom post type:
- function jr_testimonial_columns( $column, $post_id ) { switch ( $column ) {
- case "client": echo get_post_meta( $post_id, '_client_name', true); break;
- case "position": echo get_post_meta( $post_id, '_company_position', true); break;
- case "company": echo get_post_meta( $post_id, '_company_name', true); break;
- case "link": $link = get_post_meta( $post_id, '_client_link', true);
- echo '<a href="' . $link . '">' . $link. '</a>'; break;
- } }
- add_action( "manage_posts_custom_column", "jr_testimonial_columns", 10, 2 );
- // Make these columns sortable
- function jr_testimonial_sortable_columns() {
- return array('title' => 'title','client' => 'client','position' => 'position','company' => 'company','link' => 'link');
- }
- add_filter( "manage_edit-jr_testimonial_sortable_columns", "jr_testimonial_sortable_columns" );
- // Add a Custom Post Type to a feed
- function add_jr_testimonial_to_feed( $qv ) {
- if ( isset($qv['feed']) && !isset($qv['post_type']) ) $qv['post_type'] = array('post', 'jr_testimonial'); return $qv;
- }
- add_filter( 'request', 'add_jr_testimonial_to_feed' );
- /*-- End: Rotating Testimonials Post Type --*/
- STEP 2: CREATE NEW PHP FILE INSIDE YOUR /INCLUDES/ FOLDER OF THE CHILD-THEME AND NAME IT TESTIMONIALS.PHP
- :: Copy & Paste the Following ::
- <div id="testimonials">
- <?php
- $args = array( 'post_type' => 'jr_testimonial', 'posts_per_page' => 10, 'orderby' => 'menu_order', 'order' => 'ASC' );
- $loop = new WP_Query( $args ); if ( $loop->have_posts() ) : while ( $loop->have_posts() ) : $loop->the_post();
- static $count = 0; if ($count == "1") { ?>
- <div class="slide" style="display: none;">
- <div class="client-contact-info">
- <?php echo get_post_meta($post->ID, '_client_name', true); ?>,
- <?php echo get_post_meta($post->ID, '_company_position', true); ?>,
- <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>
- <div class="clear"></div>
- <div class="testimonial-quote"><?php the_content(); ?></div>
- </div>
- <?php } else { ?>
- <div class="slide">
- <div class="client-contact-info"><?php echo get_post_meta($post->ID, '_client_name', true); ?>, <?php echo get_post_meta($post->ID, '_company_position', true); ?>, <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>
- <div class="clear"></div>
- <div class="testimonial-quote"><?php the_content(); ?></div>
- </div>
- <?php $count++; } endwhile; endif; echo '</div>'; ?>
- <script type="text/javascript">
- /* <![CDATA[ */
- jQuery(document).ready(function(){ jQuery('#testimonials .slide'); setInterval(function(){
- jQuery('#testimonials .slide').filter(':visible').fadeOut(1000,function(){ if(jQuery(this).next('.slide').size())
- { jQuery(this).next().fadeIn(1000); } else { jQuery('#testimonials .slide').eq(0).fadeIn(1000); } }); },10000); });
- /* ]]> */
- </script>
- STEP 3: ADD THE FOLLOWING WHERE YOU WOULD LIKE TO HAVE TESTIMONIALS DISPLAYED, AND ADD STYLE TO IT VIA CSS
- <!-- Begin: Testimonials Panel -->
- <?php get_template_part( 'includes/testimonials' ); ?>
- <!-- Begin: Testimonials Panel -->
- ################ JUST LIKE THAT, YOU'RE DONE ################
- Icons to add to your child themes /images/ folder:
- http://postimage.org/image/ke9gwzx8t/
- http://postimage.org/image/x6xkwx8ul/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement