Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

i want get the "issue-cover" from archive page list, i done it. but it will cant get the meta value when i update/add new a post to the archice page.

<div class="monthly_archive">
    <?php $values = get_post_custom_values("issue-cover"); 
          if (isset($values[0])) { 
      ?>
    <a target="_blank" href="<?php $values = get_post_custom_values("issue-cover"); echo $values[0]; ?>" class="top-box-images"><img src="<?php $values = get_post_custom_values("issue-cover"); echo $values[0]; ?>" title="<?php echo get_post_meta($post->ID, 'issue', true); ?>"/></a>
    <?php }
        // if there's no img do replace it with no-img
     else { ?>
    <img src="<?php bloginfo('stylesheet_directory'); ?>/images/no-img.gif" title="<?php echo get_post_meta($post->ID, 'issue', true); ?>"/>
     <?php } ?>

    <span class="issue"><?php echo get_post_meta($post->ID, 'issue', true); ?></span>
    <span class="cover-by"><?php echo get_post_meta($post->ID, 'cover-by', true); ?></span>
    </div>

share|improve this question

2 Answers 2

Just wondering why you are using $values = get_post_custom_values("issue-cover"); so many times. You are missing the post->ID argument as the second parameter. You only need to define this variable once and then use it over and over.

I'm also wondering why you don't use post-thumbnails to solve this. There are two handy functions that are baked into Wordpress such as the following:

  1. has_post_thumbnail()
  2. the_post_thumbnail()

Your code would look like this:

<?php
global $post;
$values = get_post_custom_values("issue-cover", $post->ID);
$title = get_post_meta($post->ID, 'issue', true);
$designer = get_post_meta($post->ID, 'cover-by', true);
if(has_post_thumbnail()):
    echo "<a target='_blank href='{$values[0]}'>";
    the_post_thumbnail(array(HEIGHT,WIDTH), array('title'=>$title));
    echo "</a>";
else:
    echo "<img src='".get_bloginfo('stylesheet_directory')."/images/no-img.gif' title='$title' alt='$title' />";
endif;?>

To address the post meta not displaying, you will need to make sure you are operating within the loop.

share|improve this answer
    
Nice answer! I went the lazy route. It just seemed like too much to clean up. Although, warning to the OP, there is more that needs to be done to get the post thumbnails working, but it is a good recommendation to use them in this case. –  tollmanz Sep 9 '11 at 4:59
    
My theory is to use what's already baked into Wordpress whenever I can. That way I'm not adding more overhead or complexity to my theme than I need. :) –  Brian Fegter Sep 9 '11 at 5:12

Try sending the post id to the function:

$values = get_post_custom_values("issue-cover", $post->ID);

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.