Skip to content

Instantly share code, notes, and snippets.

@sunilw
Created November 5, 2014 11:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sunilw/7b552603fef7a2c8bee5 to your computer and use it in GitHub Desktop.
Save sunilw/7b552603fef7a2c8bee5 to your computer and use it in GitHub Desktop.
<?php
/*
* output all testimonial posts
*/
function stb_arr_all()
{
$args= array(
'post_type' => 'stb_testimonials'
) ;
$posts_array = get_posts($args) ;
foreach ($posts_array as $o ) {
// get the meta array for the current post
$meta = get_post_meta( $o->ID ) ;
// get the quote
echo "<blockquote><p>" . $meta['_cmb_testimonial_text']['0'] . "</p></blockquote>" ;
// get the attribution
echo "<p class='attribution'>" . $meta['_cmb_attribution']['0'] . "</p>" ;
}
}
function stb_generate_columns() {
$args= array(
'post_type' => 'stb_testimonials',
'posts_per_page' => '-1'
) ;
$posts_array = get_posts($args) ;
/*
* how many posts do we put in the first column
*/
$els = count($posts_array) ;
$half = round(($els / 2 ));
$arrOne = array_slice($posts_array, 0, $half ) ;
$arrTwo = array_slice($posts_array, $half) ;
/**
* output first half of our testimonials
*/
?>
<div id="stb-testimonials" class="group">
<div class="testimonial-col col1">
<?php
foreach ($arrOne as $o ) {
// get the meta array for the current post
$meta = get_post_meta( $o->ID ) ;
// get the quote
echo "<blockquote><p>" . $meta['_cmb_testimonial_text']['0'] . "</p></blockquote>" ;
// get the attribution
echo "<p class='attribution'>" . $meta['_cmb_attribution']['0'] . "</p>" ;
}
?>
</div> <!-- ENDS testimonial-col col1 -->
<?php
/**
* output second half of our testimonials
*/
?>
<div class="testimonial-col col2">
<?php
foreach ($arrTwo as $o ) {
// get the meta array for the current post
$meta = get_post_meta( $o->ID ) ;
// get the quote
echo "<blockquote><p>" . $meta['_cmb_testimonial_text']['0'] . "</p></blockquote>" ;
// get the attribution
echo "<p class='attribution'>" . $meta['_cmb_attribution']['0'] . "</p>" ;
}
?>
</div> <!-- ENDS testimonial-col col2 -->
</div>
<?php
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment