• Resolved Twig

    (@twig)


    Here is what I’m trying to accomplish. On the main index, I want a small image aligned left(url = the the custom field) – The title of the post and then the excerpt.

    I can get the title and excerpt styled fine, but for some reason I cannot pull the custom field data in. Here is the code I’m trying to use:

    <div class="post" id="post-<?php the_ID(); ?>">
    				<img src="<?php get_post_custom(); ?>"><b><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></b>
    				<br />

    I read the Custom Fields codex page, and from what I understand, that should input every custom field(there is only one) right there. Am I wrong?

Viewing 5 replies - 1 through 5 (of 5 total)
  • What’s your custom field called? You might be better off using get_post_meta as that can be used to only pull a single field.

    get_post_custom returns a multidimensional array – which you’d then need to loop through (even if there was only one entry) to obtain a string that you could use as your image src.

    Thread Starter Twig

    (@twig)

    Ok I see how that would work better.
    Does this seem like it should do what I’m looking for:
    <img src="<?php $meta_values = get_post_meta($post->ID, thumb, yes); ?>">

    Thread Starter Twig

    (@twig)

    Hmm… Doesn’t seem to work correctly.
    I think it’s getting stuck at the POST ID part. I obviously can’t hard code the ID in, as that wouldn’t work for The Loop. Am I doing something wrong here?

    Try <img src="<?php echo get_post_meta($post->ID, 'thumb', true); ?>">

    Thread Starter Twig

    (@twig)

    Works great. Thank you very much!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Regarding Custom Fields in the Loop’ is closed to new replies.