• Resolved pg73

    (@pg73)


    Hi

    I’ve been trying to find an answer to this for hours without success, so I really hope someone can help.

    My index page shows several recent blog posts (title, excerpt), some of these posts also have an image (which is added via a custom field). I want to be able to style the posts with images differently to those that are just text, using CSS. So I was looking to add a class name to posts that have an image.

    All I need is a way to show the ‘Name’ of a custom field, not the ‘Value’.

    Everything I’ve tried, gives me the value, or the name and value of all my custom fields. I just need the one name of a specific custom field.

    I hope that all makes sense.

    Thanks for any help.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Why not run a check to see whether or not the image has been added and the append a css class (or not) in the template?

    Thread Starter pg73

    (@pg73)

    That sounds good, but how would I go about doing that Andrew?

    What is the code to display the image in the custom field?

    Thread Starter pg73

    (@pg73)

    <?php if(get_post_custom_values('preview-image')) : foreach(get_post_custom_values('preview-image') as $image) : ?>
          <img class="post-preview-image" src="<?php echo home_url( '/' ); ?>wp-content/uploads/preview-images/<?php echo $image; ?>" />
          <?php endforeach; endif; ?>
    Thread Starter pg73

    (@pg73)

    Probably not the best way to do it, but I’ve got it working at least.

    <?php $values = get_post_custom_values("preview-image");
          if (isset($values[0])) {
          ?>
          <article <?php post_class("preview-image module-teaser") ?> id="post-<?php the_ID(); ?>" >
          <?php }
          else { ?>
          <article <?php post_class(" module-teaser") ?> id="post-<?php the_ID(); ?>" >
          <?php } ?>

    Hey there, may be this could help?

    I tried, it worked. But the problem is, I want to show the “Label” of the custom field, not the un-friendly key name like the trick does. Have you come across this need that may be you could help me?

    Thanks

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Display Custom Field 'Name' Only’ is closed to new replies.