• Okay. I’ve created a custom field in my WP photogallery, but I am still very confused on what code I need to insert into my template to get the custom field to be printed out in my index file.
    The custom field is called ‘photo_des’. What would the code look like? Is it just like a PHP include?

Viewing 6 replies - 1 through 6 (of 6 total)
  • I did one on my Pictorialis and called it Film, I am able to call it using <?php the_meta_key("Film"); ?>
    So I assume you could call yours with <?php the_meta_key("photo_des"); ?> ?

    Ah, sorry about that, I totally spaced. 🙂
    You need to have this in your my-hacks.php file:
    <?php
    function the_meta_key( $tag='') {
    global $id, $post_meta_cache;
    $inUL = false;
    if ($keys = get_post_custom_keys()) {
    foreach ($keys as $key) {
    if ($key == $tag || $tag=='') {
    $values = array_map('trim',$post_meta_cache[$id][$key]);
    $value = implode($values,', ');
    if (!$inUL) { echo "<ul class='post-meta'>\n"; $inUL = true; }
    echo "

    • <span class='post-meta-key'>$key:</span> $value
    • \n";
      }
      }
      if ($inUL) { echo "
      \n"; }
      }
      }
      ?>

    Here’s the thread I originally got this from, in case you have issues:
    http://wordpress.org/support/3/6283

    Why are we required to have a my hacks file for this feature within WP? I would like to avoid having customized files all over the place and never liked the hacks file to begin with (I don’t want to have to create or maintain one for each upgrade, etc.). If Custom Fields is a core part of the new version of WP, shouldn’t there be something we can just put in our templates to make them appear without using another file?

    That hack should be added to the WordPress Wiki 🙂

    debwire: this can very simply be made a plugin

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘How do I display a custom field?’ is closed to new replies.