This is searchable archive of our old support forums, which operated from 2012 - 2016. To find out how to get support for your current theme, please visit our support page.

post-grid short code: How to show featured image caption

  • Creator
    Topic
  • #10458
    pzanon
    Participant

    I realize this may be question related to Theme Options (Post Grid), but I wonder how to get the caption of the featured image to display when I use the [post_grid] short code.

Viewing 7 replies - 1 through 7 (of 7 total)
  • Author
    Replies
  • #10474
    Jason Bobich
    Keymaster

    Hello,

    Unfortunately there’s no option in the theme for this. If you’d like to edit how posts are displayed in a post grid, you’d copy content-grid.php to your Child theme to edit. You’d need to rig up something custom there to pull the caption for the featured image attachment’s caption.

    http://dev.themeblvd.com/tutorial/editable-content-files/

    http://wordpress.org/support/topic/featured-image-display-image-caption

    http://wordpress.org/support/topic/display-caption-with-the_post_thumbnail?replies=10

    #10489
    pzanon
    Participant

    I copied content-grid.php to the Child Theme and after the place where the post is pulled in:

    I added this code:

    ‘attachment’,
    ‘post_status’ => null,
    ‘post_parent’ => the_ID(),
    ‘include’ => $thumb_id
    );
    $thumbnail_image = get_posts($args);

    if ($thumbnail_image && isset($thumbnail_image[0])) {
    echo $thumbnail_image[0]->post_excerpt;
    }
    ?>

    It indeed retrieves the caption of the featured image, but also precedes the ID twice, once coming from the variable $thumb_id and once from the variable $thumbnail_image.

    How can I get rid of that? Thanks,
    Philip

    #10491
    pzanon
    Participant

    oh sorry, just realized that I need to paste the code differently @#$!**** pasties doesn’t seem to work.

    so here again with out the php tags:

    After

    themeblvd_the_post_thumbnail( themeblvd_get_att( 'location' ), themeblvd_get_att( 'crop' ) );

    I added:

    $thumb_id = get_post_thumbnail_id(the_ID());
    				 $args = array(
    				'post_type' => 'attachment',
    				'post_status' => null,
    				'post_parent' => the_ID(),
    				'include'  => $thumb_id
    				); 
       			$thumbnail_image = get_posts($args);
      		        if ($thumbnail_image && isset($thumbnail_image[0])) {
            			echo $thumbnail_image[0]->post_excerpt; 
    				}

    Thanks, Philip

    #10507
    Jason Bobich
    Keymaster

    I’m sorry but I don’t understand the issue. Maybe you could link to an example of the outputted result?

    And if you want to paste any code here into the forum, just put it within pre html tags.

    #10554
    pzanon
    Participant

    Sorry, to be unclear… The site is not accessible from public yet. So far I have what I need, but it may not be the most elegant way. I am posting below the entire content-grid.php as I have it copied to the child theme. I had to use the hidden feature to get rid of the output of the image ids. As I said, not elegant but it works. Thanks for the help.

    <?php
    /**
     * The template used for displaying posts in a grid.
     */
    $excerpt = themeblvd_get_option( 'post_grid_excerpt', null, 'hide' );
    $button = themeblvd_get_option( 'post_grid_button', null, 'hide' );
    
    ?>
    <div class="grid-item column <?php echo themeblvd_get_att( 'size' ); ?><?php if( themeblvd_get_att( 'counter' ) % themeblvd_get_att( 'columns' ) == 0 ) echo ' last'; ?>">
    	<div class="article-wrap">
    		<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    			<div class="entry-content<?php if( $excerpt == 'show' && $button == 'show' ) echo ' has_elements'; ?>">   
    				<?php themeblvd_the_post_thumbnail( themeblvd_get_att( 'location' ), themeblvd_get_att( 'crop' ) ); ?>
    			
           
            <?php
    // This is the code that retrieves the caption of the featured image      
    				 echo '<p hidden>';
    				 $thumb_id = get_post_thumbnail_id(the_ID());
    
    				 $args = array(
    				'post_type' => 'attachment',
    				'post_status' => null,
    				'post_parent' => the_ID(),
    				'include'  => $thumb_id
    				); 
    
       			$thumbnail_image = get_posts($args);
    				echo '</p>';
            
      		  if ($thumbnail_image && isset($thumbnail_image[0])) {
        			// this line outputs the caption
        			 echo $thumbnail_image[0]->post_excerpt; 
    					 }           
            ?>      
            
            
            <?php if( 'show' == themeblvd_get_option( 'post_grid_title', null, 'show' ) ) : ?>
    					<h2 class="entry-title"><?php themeblvd_the_title(); ?></h2>
    				<?php endif; ?>
    				<?php if( 'show' == $excerpt ) : ?>
    					<?php the_excerpt(); ?>
    				<?php endif; ?>
    				<?php if( 'show' == $button ) : ?>
    					<p><?php echo themeblvd_button( themeblvd_get_local( 'read_more' ), get_permalink( get_the_ID() ), 'default', '_self', 'small', 'read-more', get_the_title( get_the_ID() )  ); ?></p>
    				<?php endif; ?>
    			</div><!-- .entry-content -->
    		</article><!-- #post-<?php the_ID(); ?> -->
    	</div><!-- .article-wrap (end) -->
    </div><!-- .grid-item (end) -->
    #10555
    Jason Bobich
    Keymaster

    Aw, I understand now. This part:

    $thumb_id = get_post_thumbnail_id(the_ID());

    Should be this:

    $thumb_id = get_post_thumbnail_id( get_the_ID() );

    This is a common naming convetion in many of WordPress’s functions. You’ll have something that prints out like the_ID(), and then many times you’ll also have a function named the same thing but with get_ at the start, which returns the value instead.

    #10577
    pzanon
    Participant

    Thanks for this, one step closer – yet if I use:

    $args = array(
    				'post_type' => 'attachment',
    				'post_status' => null,
    				'post_parent' => get_the_ID(),
    				'include'  => $thumb_id
    				); 
       			$thumbnail_image = get_posts($args);

    Then, the caption doesn’t appear. If I go back to:

    $args = array(
    				'post_type' => 'attachment',
    				'post_status' => null,
    				'post_parent' => the_ID(),
    				'include'  => $thumb_id
    				); 
       			$thumbnail_image = get_posts($args);

    Then, the variable $thumbnail_image will echo the featured image ID, which I still have to hide. I can live with that, but it may be nice to have a cleaner version to share with others who would like to show the caption.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The forum ‘Akita Responsive WordPress Theme’ is closed to new topics and replies.