Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@BronsonQuick
Created March 9, 2014 06:00
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save BronsonQuick/9443465 to your computer and use it in GitHub Desktop.
Save BronsonQuick/9443465 to your computer and use it in GitHub Desktop.
Displaying CMB data example for JohnLion
<?php function sz_get_testimonials( $page_id ){
$testimonials = get_post_meta( $page_id, 'testimonial', false );
if ( $testimonials ) {
$testimonial_list = "\n<ul>\n";
foreach ( $testimonials as $testimonial ) {
$testimonial_image = false;
$testimonial_content = false;
$testimonial_list .= "\t<li class='row'>";
if ( $testimonial['testimonial-image'] ) {
$testimonial_image = wp_get_attachment_image( $testimonial['testimonial-image'], 'full', '', array( 'class' => 'columns small-3' ) );
}
if ( $testimonial['testimonial-content'] ) {
$testimonial_content .= "<div class='columns small-9'>";
$testimonial_content .= wpautop( $testimonial['testimonial-content'] );
$testimonial_content .= "</div>";
}
$testimonial_list .= $testimonial_image;
$testimonial_list .= $testimonial_content;
$testimonial_list .= "</li>\n";
}
$testimonial_list .= "</ul>\n";
return $testimonial_list;
}
else {
return false;
}
}
function sz_the_testimonials( $page_id ) {
if ( sz_get_testimonials( $page_id ) ) {
echo sz_get_testimonials( $page_id );
}
else {
return false;
}
}
@j-mccarthy
Copy link

Thanks again for sharing this code. I've now used it in my project, extended it to out put more fields and used the method for many more sections of my site. How good are template tags!!! I used them a little a the beginning of the year, I was learning so much at the time that they slipped through. Wow, one line of code in the page template. So nice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment