WordPress.org

Ready to get started?Download WordPress

Forums

media description not showing up (13 posts)

  1. kikib
    Member
    Posted 9 months ago #

    I'm trying to display the description of an image on my homepage. However, I'm working on my wp website by localhost. Here's my code

    <div id="featured">
    	 <div class="featuredtext">
            <h2><span>Featured Art Work</span></h2>
        </div>
    <?php query_posts('cat=18&showposts=1'); ?>
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    
        <div id="featuredpic" class="featured_item">
        	<?php //get article_image (custom field) ?>
            <?php $image = get_post_meta($post->ID, 'featured_image', true); ?>
    
            <a href="<?php the_permalink(); ?>"><img src="<?php echo $image; ?>" alt="Featured Artwork" /></a>
            <span class="caption featuredtitle">
              <div id="feattitle"><h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
              </div>
              <div id="featureddescription"><?php echo $description = $image->post_content; ?>
             </div>
           </span>
        </div>
         <hr class="border" />
     </div>

    <div id="featureddescription"><?php echo $description = $image->post_content; ?></div>

    This excerpt was taken out of the code box to emphasis where I'm trying to post the description of a media image. But it's not showing up on the page. What do I do?

  2. esmi
    Theme Diva & Forum Moderator
    Posted 9 months ago #

    By description, do you mean the image's caption?

  3. kikib
    Member
    Posted 9 months ago #

    I was looking at the media image and it does display the caption and the description.

  4. esmi
    Theme Diva & Forum Moderator
    Posted 9 months ago #

    So - not the caption? I think you may need to run a secondary loop to display this information via the_content().

  5. kikib
    Member
    Posted 9 months ago #

    So it's best to display the caption then? I only wanted to display words about image when people hover over the image.

  6. esmi
    Theme Diva & Forum Moderator
    Posted 9 months ago #

    "best" is very subjective but it would certainly be easier to display the caption rather than the description. I've not tried it with the caption shortcode but, in theory, it should be possible to use something like:

    echo do_shortcode('[caption]<img src="' . $image . " alt="Featured Artwork" />[/caption]');

    to display the image and it's caption. Then you'd need to play with CSS to hide the caption text until the image is hovered over or has focus.

  7. kikib
    Member
    Posted 9 months ago #

    I'm not displaying an image because it's already displayed in

    <div id="featuredpic" class="featured_item">
        	<?php //get article_image (custom field) ?>
            <?php $image = get_post_meta($post->ID, 'featured_image', true); ?>

    I got this tutorial from http://dinolatoga.com/2009/09/18/amazing-imag-hover-effects-with-webkit-and-css/ with slide in box effect and modified it in wordpress.

    So to display the caption, I would need to write

    <?php echo do_shortcode('[caption] />[/caption]'); ?>

    right?

  8. esmi
    Theme Diva & Forum Moderator
    Posted 9 months ago #

    No - the caption shortcode displays the image and the caption.

  9. kikib
    Member
    Posted 9 months ago #

    So, how do I display only the caption?

    <?php the_caption() ?> , right?

  10. esmi
    Theme Diva & Forum Moderator
    Posted 9 months ago #

    You could try using something based on:

    $image_post = get_post($id);
    // description
    $desc= $image_post->post_content;
    // caption
    $caption= $image_post->post_excerpt;

    Thinking about it, it would be a lot easier if your post meta stored the image's post id rather than it's url. Otherwise things could get a bit messy.

  11. kikib
    Member
    Posted 9 months ago #

    I couldn't get it to work...

    do I post it like this?

    <?php $caption= $image_post->post_excerpt; ?>

    or just

    <p>$caption= $image_post->post_excerpt;</p> ?

  12. esmi
    Theme Diva & Forum Moderator
    Posted 9 months ago #

    <?php $caption= $image_post->post_excerpt;
    echo $caption; ?>
  13. kikib
    Member
    Posted 9 months ago #

    I couldn't get it to work but I changed several things to make it works.

    Here's the new code after I added the custom field "featured_text" to the post.

    <div id="featured">
    	 <div class="featuredtext">
            <h2><span>Featured Art Work</span></h2>
        </div>
    <?php query_posts('cat=18&showposts=1'); ?>
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    
        <div id="featuredpic" class="featured_item">
        	<?php //get article_image (custom field) ?>
            <?php $image = get_post_meta($post->ID, 'featured_image', true); $caption= get_post_meta($post->ID, 'featured_text',true); ?>
    
            <a href="<?php the_permalink(); ?>"><img src="<?php echo $image; ?>" alt="Featured Artwork" /></a>
            <span class="caption featuredtitle"><div id="feattitle"><h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2></div><div id="featureddescription"><p><?php echo $caption; ?></p></div></span>
    
        </div>
         <hr class="border" />
     </div>

Reply

You must log in to post.

About this Topic