Forums

[resolved] [Plugin: Custom Field Template] how do i display the image or file? (4 posts)

  1. bruzed
    Member
    Posted 3 weeks ago #

    one of my custom fields is to display an image. the upload seems to work fine:

    [Picture]
    type=file
    relation=true
    class=file
    multiple=true

    the code i'm using to display all the other fields is below. this is obviously wrong. please help.


    <?php
    $block = get_post_meta($post->ID, 'Picture');
    foreach(($block) as $blocks) {
    echo $blocks;
    }
    ?>

    thanks in advance!

  2. hiroshikun
    Member
    Posted 3 weeks ago #

    i have the same problem,
    i search on the db and in the values
    of the custom fields
    i found that the attachment id is stored on the
    field, but i don't know how use the id to get the picture
    from the database

    if there is a way to get the picture by id a function to
    get the picture can do the work

    but this part is a mistery for me

  3. Hiroaki Miyashita
    Member
    Posted 2 weeks ago #

    There are several functions in order to display the image. This is an example.

    Template Content

    [thumbnail_id]
    type = file
    relation = true

    In the loop of the theme files like index.php, single.php, etc:

    <?php
    $thumbnail_id = get_post_meta($post->ID, 'thumbnail_id', true);
    echo wp_get_attachment_image($thumbnail_id, 'thumbnail');
    ?>

    I hope this will help you.

  4. bruzed
    Member
    Posted 2 weeks ago #

    thanks hiroaki that works perfectly!

Reply

You must log in to post.

About this Topic