Thursday, 20 December 2012

How to Add Rotating Testimonials in WordPress



Recently, we had to create a rotating testimonials display in WordPress for one of our clients. We did a brief search on the web, but we did not find a plugin that did what we wanted. Rather than spending a lot of time finding the right plugin, we decided to create this from scratch. In this article, we will show you how you can create a rotating testimonials area in WordPress where testimonials fade in and out automatically. You can use this technique for other uses as well such as quotes, fun facts, etc.
Note: You need to have a fair understanding of how WordPress work in order to follow this tutorial.
The approach we took was like this: Register a custom post type and call it Testimonials. We wanted to show information like: Client’s name, their position in the company, company name, and link to our portfolio page. Instead of using custom fields, we decided to add a custom meta boxes to make it easy for our client to enter the information. Last but certainly not least, add JavaScript fadeIn and fadeOut to rotate the testimonials on the same page. Obviously it is hard to show a live demo of it on this page, but if you know how fadeIn and fadeOut works, then you get the point.

Step 1: Register a Custom Post Type

We won’t go in lengthy explanation of how to create a Custom Post Type. We have already written an article about creating custom post types in WordPress. That article has a video that will explain the process. It also shows the plugin method rather than the hard code method. Now if you want to call your custom post type “Testimonials”, then all you have to do is paste the following code in your theme’s functions.php file.

==============================================================

add_action( 'init', 'wpb_register_cpt_testimonial' );

function wpb_register_cpt_testimonial() {

    $labels = array(
        'name' => _x( 'Testimonials', 'testimonial' ),
        'singular_name' => _x( 'testimonial', 'testimonial' ),
        'add_new' => _x( 'Add New', 'testimonial' ),
        'add_new_item' => _x( 'Add New testimonial', 'testimonial' ),
        'edit_item' => _x( 'Edit testimonial', 'testimonial' ),
        'new_item' => _x( 'New testimonial', 'testimonial' ),
        'view_item' => _x( 'View testimonial', 'testimonial' ),
        'search_items' => _x( 'Search Testimonials', 'testimonial' ),
        'not_found' => _x( 'No testimonials found', 'testimonial' ),
        'not_found_in_trash' => _x( 'No testimonials found in Trash', 'testimonial' ),
        'parent_item_colon' => _x( 'Parent testimonial:', 'testimonial' ),
        'menu_name' => _x( 'Testimonials', 'testimonial' ),
    );

    $args = array(
        'labels' => $labels,
        'hierarchical' => false,
       
        'supports' => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'custom-fields', '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( 'testimonial', $args );
}
==============================================================

Step 2: Adding Custom Meta Boxes

As explained earlier, the information we wanted to display included:
  • Person’s Name who is giving the Testimonial
  • Their position in the Company
  • Company Name
  • Link to the company page on our Portfolio
  • Testimonial test (which will be the post body)
Now you can go and use custom fields if you like, but we prefer to have a nicer display that makes it easy for anyone to enter the information. The code we used to add the meta box goes like this: (Note: you would need to paste this in your theme’s functions.php file)

==============================================================

$key = "testimonial";
$meta_boxes = array(
"person-name" => array(
"name" => "person-name",
"title" => "Person's Name",
"description" => "Enter the name of the person who gave you the testimonial."),
"position" => array(
"name" => "position",
"title" => "Position in Company",
"description" => "Enter their position in their specific company."),
"company" => array(
"name" => "company",
"title" => "Company Name",
"description" => "Enter the client Company Name"),
"link" => array(
"name" => "link",
"title" => "Client Link",
"description" => "Enter the link to client's site, or you can enter the link to your portfolio page where you have the client displayed.")
);

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', 'testimonial', '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' );
==============================================================


Now if you go and try to add a New Testimonial, you will have a custom meta box like the one in the image below:
Testimonial Meta Box
If you want to add additional fields to the meta boxes, you can simply add them into the $meta_boxes = array(. If you don’t understand the code above, but still want to add additional fields, then perhaps you should consider using a plugin called More Fields (Video Tutorial).

Step 3. Displaying the Rotating Content

First thing we need to do is add the JavaScript that will rotate the content.

==============================================================

<script language="javascript">
$(document).ready(function(){
$('#testimonials .slide');
setInterval(function(){
$('#testimonials .slide').filter(':visible').fadeOut(1000,function(){
if($(this).next('.slide').size()){
$(this).next().fadeIn(1000);
}
else{
$('#testimonials .slide').eq(0).fadeIn(1000);
}
});
},15000);
});
</script>
==============================================================


Make sure that jQuery is being loaded in the header already. If it is not, then you would need to add that as well.
Next we will create the loop that will display the testimonials. The code we used is below:
==============================================================<div id="testimonials">
<?php
$args = array( 'post_type' => 'testimonial', 'posts_per_page' => 10 );
$loop = new WP_Query( $args );
if ( $loop->have_posts() ) : while ( $loop->have_posts() ) : $loop->the_post();
$data = get_post_meta( $loop->post->ID, 'testimonial', true );
static $count = 0;
if ($count == "1") { ?>



<div class="slide" style="display: none;">
<div class="client-contact-info"><?php echo $data[ 'person-name' ]; ?>,&nbsp;<?php echo $data[ 'position' ]; ?>,&nbsp;<a href="<?php echo $data[ 'link' ]; ?>" title="<?php echo $data[ 'company' ]; ?>"><?php echo $data[ 'company' ]; ?></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 $data[ 'person-name' ]; ?>,&nbsp;<?php echo $data[ 'position' ]; ?>,&nbsp;<a href="<?php echo $data[ 'link' ]; ?>" title="<?php echo $data[ 'company' ]; ?>"><?php echo $data[ 'company' ]; ?></a></div>
<div class="clear"></div>
<div class="testimonial-quote"><?php the_content(); ?></div>
</div>

<?php 
$count++; } 
endwhile; 
endif; ?>
</div>
==============================================================


You would need to paste the above code anywhere you want to display the testimonial. Whether it is on your homepage, custom page template, sidebar, or footer. Pick a place and paste the code.
A little explanation to why this loop is a bit more complicated then a normal loop. First thing we do is tell the loop that we want to pull posts from the post type “testimonial”. Next thing we tell it is that only show 10 recent testimonials. The way our JavaScript works is that we need to only show the first post. The other 9 has to be invisible, so it can fadein and fadeout.
Now once you have pasted the code above, you need to style it.
==============================================================
#testimonials{}
#testimonials .slide{color: #9c968e;}
#testimonials .client-contact-info{margin: 25px 0 0 0; float: left;}
#testimonials .testimonial-quote{padding: 3px 0 0 65px; line-height: 1.5em; font-family: "proxima-nova-1", "proxima-nova-2", Helvetica, Arial, sans-serif !important; font-size: 16px; font-weight: normal; font-style: italic; margin: 10px 0 20px 0;}
==============================================================
Now the output of our code will look like this:
Client Name, Their Position in the Company, Company Name (hyperlinked)
Testimonial Text
Example:
Syed Balkhi, Founder, WPBeginner
This quote this is pretty cool.
Few things to note in the tutorial, if you do add additional fields, you will have to add it to the loop. You can change the styling however you want.
Because this thing is very specific, we thought it was not worth releasing a plugin for it. However, if you are looking to do the exact same thing we did, and want to have the exact same display that we have, then you are in luck.
Simply create a new file and call it testimonials.php and save it in your plugin’s folder (/wp-content/plugins/). Then paste the following code in there:
==============================================================
<?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( 'Testimonials', 'testimonial' ),
        'singular_name' => _x( 'testimonial', 'testimonial' ),
        'add_new' => _x( 'Add New', 'testimonial' ),
        'add_new_item' => _x( 'Add New testimonial', 'testimonial' ),
        'edit_item' => _x( 'Edit testimonial', 'testimonial' ),
        'new_item' => _x( 'New testimonial', 'testimonial' ),
        'view_item' => _x( 'View testimonial', 'testimonial' ),
        'search_items' => _x( 'Search Testimonials', 'testimonial' ),
        'not_found' => _x( 'No testimonials found', 'testimonial' ),
        'not_found_in_trash' => _x( 'No testimonials found in Trash', 'testimonial' ),
        'parent_item_colon' => _x( 'Parent testimonial:', 'testimonial' ),
        'menu_name' => _x( 'Testimonials', 'testimonial' ),
    );

    $args = array( 
        'labels' => $labels,
        'hierarchical' => false,
        
        'supports' => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'custom-fields', '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( 'testimonial', $args );
}

$key = "testimonial";
$meta_boxes = array(
"person-name" => array(
"name" => "person-name",
"title" => "Person's Name",
"description" => "Enter the name of the person who gave you the testimonial."),
"position" => array(
"name" => "position",
"title" => "Position in Company",
"description" => "Enter their position in their specific company."),
"company" => array(
"name" => "company",
"title" => "Company Name",
"description" => "Enter the client Company Name"),
"link" => array(
"name" => "link",
"title" => "Client Link",
"description" => "Enter the link to client's site, or you can enter the link to your portfolio page where you have the client displayed.")
);
 
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', 'testimonial', '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() { ?>
<script language="javascript"> 
$(document).ready(function(){
$('#testimonials .slide');
setInterval(function(){
$('#testimonials .slide').filter(':visible').fadeOut(1000,function(){
if($(this).next('.slide').size()){
$(this).next().fadeIn(1000);
}
else{
$('#testimonials .slide').eq(0).fadeIn(1000);
}
});
},15000);
});
</script> 
<style type="text/css">
#testimonials .slide{color: #9c968e;}
#testimonials .client-contact-info{margin: 25px 0 0 0; float: left;}
#testimonials .testimonial-quote{background: url(images/quotebg.png) repeat-y; padding: 3px 0 0 65px; line-height: 1.5em; font-family: "proxima-nova-1", "proxima-nova-2", Helvetica, Arial, sans-serif !important; font-size: 16px; font-weight: normal; font-style: italic; margin: 10px 0 20px 0;}
</style>
<div id="testimonials">
<?php
$args = array( 'post_type' => 'testimonial', 'posts_per_page' => 100, '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, 'testimonial', true );
static $count = 0;
if ($count == "1") { ?>



<div class="slide" style="display: none;">
<div class="client-contact-info"><?php echo $data[ 'person-name' ]; ?>,&nbsp;<?php echo $data[ 'position' ]; ?>,&nbsp;<a href="<?php echo $data[ 'link' ]; ?>" title="<?php echo $data[ 'company' ]; ?>"><?php echo $data[ 'company' ]; ?></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 $data[ 'person-name' ]; ?>,&nbsp;<?php echo $data[ 'position' ]; ?>,&nbsp;<a href="<?php echo $data[ 'link' ]; ?>" title="<?php echo $data[ 'company' ]; ?>"><?php echo $data[ 'company' ]; ?></a></div>
<div class="clear"></div>
<div class="testimonial-quote"><?php the_content(); ?></div>
</div>

<?php 
$count++; } 
endwhile; 
endif;
echo '</div>';
}
?>
==============================================================


Now open any theme file of yours where you want to display this, and simply paste the following code:
==============================================================
<?php wpb_display_testimonials(); ?>
==============================================================


You can simply override the style files if you look above. Note: if jQuery is not being added in your theme already, then you will have to add it.

Apply beautiful photo filters on your WordPress images


Power up your WordPress site with InstaFX. Apply beautiful photo filters on your WordPress images. The main focus of InstaFX is manipulating images using the HTML5 canvas and Javascript. It’s a combination of a simple-to-use interface with advanced and efficient image/canvas editing techniques.

With InstaFX, self-hosted WordPress users can now enjoy the ease of applying retro-style photo filters on their image uploads, an experience that used to belong exclusively to smartphone owners. Our team thinks that the WordPress community deserves what avid users of Instagram, Facebook, and Twitter have had in months and even years.
For this initial release, there are 11 different photo filters available and they are all equally beautiful. More filters are coming your way as we’ll be continuously adding more features and improving the overall user interface.
For example, if you want to display image with filter, you just need to insert the following shortcode:
  • [instafx src="" width="" height="" title="" rel="" class="" id="" before="" after="" effect="" ]
  • [instafx src="" width="" height="" title="" rel="" class="" id="" before="" after="" effect="" ] Your Content contain image [/instafx]
  • [instafx width="" height="" title="" rel="" class="" id="" before="" after="" effect="" ] Your Content contain image [/instafx]

Default filters:

  • Majesty
  • Sunrise
  • Cross
  • Peel
  • Love
  • Pinhole
  • Glowing
  • Hazy
  • Nostalgia
  • Hemingway
  • Boot
Plugin Details
  • Version: 1.0
  • Last Updated: 17 December 2012
  • Released: 12 December 2012
  • Short URL: http://colorlabs.co/STaUna
  • Compatible up to: WordPress 3.4.2
  • Downloads: 157

Thursday, 1 November 2012

7 Eleven: Free Three Samsung Galaxy Note 10.1 Tablets Giveaway



Slurpee wants you to enjoy your favourite 
brain-freezing drink just the way you like it – 
in your own mug, and only 
for the price of RM 2.20. 

 Take a picture of your drink and send it to 711day@7eleven.com.my to 
stand a chance to 
win one of three Samsung Galaxy Note 10.1 tablets.

Promotions > Burger King FREE ala carte Burger (PRINT VOUCHER)



Redemption details: Print the original voucher via link below on Burger King Malaysia Facebook to get 1 FREE alacarte burger with each Nescafe Ice purchase - RM4.55 before tax. (Photo above is for sample illustration purpose)

Redemption period: Till 23rd November 2012

Redemption outlets: ALL Burger King except KLIA and Sabah outlets.

Terms and conditions: 
Voucher must be printed to redeem. One free burger with every Nescafe Ice purchase. Invalid for BK Hottest Deals, BK Delivery and other promotions. This promotion is not applicable in KLIA and Sabah Outlets.

Website: https://www.facebook.com/bkmalaysia/app_160291820682178

Wednesday, 31 October 2012

GSC European Union Film Festival: Free Movie Passes Giveaway


In conjunction with the 13th European Union Film Festival,
the delegation of the European Union to Malaysia
is offering 100 pairs of general complimentary passes,
which is valid at ALL EUFF screening locations,
to view any of the film included in the list
(except for Senna, Mataharis and Pina 3D)
To redeem,
simply cut your vouchers from The Star Newspaper
(1st November 2012, Star 2, Page 19)
and redeem it at GSC MidValley
(Gold Class Counter)
by 2nd November 2012, 11am onwards

Screening Date and Outlets
  • 1Utama, Midvalley, Pavilion KL (8 – 18 November 2012);
  • Gurney Plaza, Penang (22 – 28 November 2012);
  • Suria Sabah, Kota Kinabalu (6 – 13 December 2012). Suria Sabah
Terms and conditions
  • Only original coupons will be accepted (no photocopies, please)
  • Each coupon redeems two passes, on a first-come, first-served basis while stocks last.
  • Each person is entitled to redeem a maximum of two passes only.
  • The method of distributing the passes is at the sole discretion of the organizer and no correspondence will be entertained.

Tuesday, 30 October 2012

Golden Screen Cinemas Amanjaya Mall: Free Screening Giveaway


Golden Screen Cinemas is giving away free movie tickets

Celebrating New Opening
@ GSC Amanjaya Mall, Sungai Petani on 1 November 2012
GSC is giving away free movie passes
from 1 – 4 November 2012
Free Movie Screening
  • The Amazing Spiderman
  • Brave (Digital 2D)
  • Mael Lambong (Bahasa Malaysia)
  • Motorway (Kantonis) (Digital 2D)

Monday, 29 October 2012

Airasia: Free Seats Giveaway



Airasia will be giving free seats on this 
coming 29 October 2012.

Don't forget to mark your calendar!