Created
November 30, 2012 01:49
-
-
Save senlin/4173225 to your computer and use it in GitHub Desktop.
Testimonials Page Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** Template Name: Testimonials */ | |
get_header(); ?> | |
<div class="page-header"> | |
<h1 class="page-title"> | |
<?php _e( 'Testimonials', 'basejump' ); ?> | |
</h1> | |
</div><!-- end .page-header --> | |
<div <?php post_class(); ?>> | |
<div class="entry-content"> | |
<?php // the normal Loop that calls the_content() of the Testimonials Page | |
while ( have_posts() ) : the_post(); the_content(); endwhile; ?> | |
<div id="testimonials"> | |
<hr class="fade" /> | |
<div class="wrap"> | |
<?php // The CPT query that also adds a class to every 4th post (in this case) to make the columns work in my Basejump theme | |
//new query add class first via http://wordpress.org/support/topic/adding-a-different-class-to-every-third-post#post-1630969 | |
// first the arguments of the query: | |
$args = array( 'post_type' => 'testimonial', 'posts_per_page' => 6, 'orderby' => 'rand' ); | |
// define the loop | |
$loop = new WP_Query( $args ); | |
if ( $loop->have_posts() ) : $i = 0; while ( $loop->have_posts() ) : $loop->the_post(); $i++; | |
// add additional class to every 4th post | |
if ( $i == 4) { | |
$style = 'one-third testimonial first'; | |
$i = 0; } | |
else { $style = 'one-third testimonial'; } | |
// resize the featured image (I have uploaded small images so I can call the full image and resize that to a square hard-cropped thumb) | |
$testimonial_image = aq_resize( wp_get_attachment_url( get_post_thumbnail_id() ,'full' ), 96, 96, true ); | |
?> | |
<div <?php post_class($style) ?>> | |
<a href="<?php echo get_permalink(); ?>"> | |
<img class="frame center" src="<?php echo $testimonial_image ?>" title="<?php echo get_the_excerpt(); ?>" alt="<?php echo get_the_title(); ?>" /> | |
</a> | |
<?php // I use the metabox plugin (http://wordpress.org/extend/plugins/meta-box/) to add custom metaboxes to my CPT and here I echo these data ?> | |
<div class="client"><?php echo rwmb_meta( '_SO_client' ) ?></div> | |
<div class="company"><?php echo rwmb_meta( '_SO_company' ) ?></div> | |
</div><!--end .one-third testimonial--> | |
<?php | |
endwhile; | |
wp_reset_postdata(); | |
endif; ?> | |
</div><!--end .wrap--> | |
</div><!--end #testimonials--> | |
<div class="clear"></div> | |
</div><!-- end .entry-content --> | |
</div><!-- end .post_class --> | |
<?php get_footer();?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
salam