Displaying Data in Shordcode
-
I have been trying to figure out why
$cover_img = get_post_meta( $post->ID, 'dc_sermons_dc_cover_img', true );
Isn’t displaying in my shortcode loop. The shortcode is on the home page if that matters. Any ideas?
Here is my shortcode:
add_shortcode( 'sermon-hub', 'dc_simple_shortcode' ); function dc_simple_shortcode( $atts ) { ob_start(); global $query; $query = new WP_Query( array( 'post_type' => 'sermon_hub', 'posts_per_page' => 3, 'meta_key' => 'dc_sermons_dc_date', 'orderby' => 'meta_value', 'order' => 'DESC' ) ); if ( $query->have_posts() ) { ?> <div class="dc-grid" style="width:100%; max-width:1020px; padding-top:25px;"> <?php while ( $query->have_posts() ) : $query->the_post(); ?> <div class="dc-col-1-3 blurb-ripple-out" style="position:relative;"> <div class="dc-post-container" style="<?php $show_shadow = dcoptions_get_option( 'short_shadow' ); if ( $show_shadow == 'false') { echo 'box-shadow:none !important; -webkit-box-shadow:none; -moz-box-shadow:none; -o-box-shadow:none; border-radius: 0px;'; }?> background-color:<?php echo dcoptions_get_option( 'short_box_bg' ); ?>;"> <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"> <?php $cover_img = get_post_meta( $post->ID, 'dc_sermons_dc_cover_img', true ); $default_img = dcoptions_get_option( 'default_sermon_image' ); $site_url = get_site_url(); if ( !empty($cover_img) ) { echo '<img style="border-radius:8px;" class="sermon_cover_image" src="'. $cover_img . '" />'; } else if ( !empty($default_img) ) { echo '<img style="border-radius:8px;" src="'. $default_img .'" />'; } else { echo '<img style="border-radius:8px;" src="'. $site_url .'/wp-content/plugins/sermon-hub-plugin/img/default-sermon-img.jpg" />'; } ?> </a> <div style="text-align:center; <?php $show_player = dcoptions_get_option( 'short_play' ); if ( $show_player == 'false') { echo 'display:none !important;'; } else { echo ''; }?>"><a href="<?php the_permalink(); ?>"><span class="dc-player-icon"></span></a></div> <div class="dc-echo-post-data-a" style=""> <h2 style="text-align:center; <?php $show_details = dcoptions_get_option( 'short_title' ); if ( $show_details == 'false') { echo 'display:none !important;'; } else { echo ''; }?>"><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2> <div style="text-align:center; <?php $show_details = dcoptions_get_option( 'short_preacher' ); if ( $show_details == 'false') { echo 'display:none !important;'; } else { echo ''; }?>"> <?php $terms = get_the_terms( $post->ID, 'preacher', true ); if ( empty($terms)) { echo ''; } else if( $terms && ! is_wp_error( $terms ) ) { foreach( $terms as $term ) { echo '<span>by ' . esc_attr( $term->name ) . '</span> '; } } ?> </div> </div> </div> </div> <?php endwhile; wp_reset_postdata(); ?> </div> <style> .blurb-ripple-out .dc-player-icon:before { border: <?php echo dcoptions_get_option( 'archive_play_button' ); ?> solid 6px; } .dc-player-icon { background-color: <?php echo dcoptions_get_option( 'archive_play_button' ); ?>; } <?php $show_shadow = dcoptions_get_option( 'short_shadow' ); if ( $show_shadow == 'false') { echo ' .dc-post-container img { border-radius: 10px !important; } '; } ?> @media all and (min-width: 768px) and (max-width: 1100px) { [class*="dc-col-"] { width: 33.33% !important; padding-left: 0px !important; padding-bottom: 0px !important; } } </style> <?php $myvariable = ob_get_clean(); return $myvariable; } }
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Displaying Data in Shordcode’ is closed to new replies.