WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] [Plugin: Custom Field Template] File and Image Display (13 posts)

  1. MissDanni
    Member
    Posted 4 years ago #

    I am setting up a themes site where the member can upload both a screenshot and a zip file

    The file id is indeed being stored in the database but the files are not attached to the posts.

    This is what I am trying to use.

    [Theme Image]
    type = file
    relation = true
    
    [Theme Upload]
    type = file
    relation = true

    I want both the thumbnail image alignleft and a download link at the bottom of the post.

    I have tried using the following in the loop to no avail.

    <?php
    $Theme Image = get_post_meta($post->ID, 'Theme Image', true);
    echo wp_get_attachment_image($Theme Image, 'screenshot');
    ?>
    
    <?php
    $Theme Upload = get_post_meta($post->ID, 'Theme Upload', true);
    echo wp_get_attachment($Theme Upload, 'Download');
    ?>

    What I'm doing is obviously wrong, a bit of guidance would be nice.

  2. MissDanni
    Member
    Posted 4 years ago #

    Ok I got the image thumbnail issue worked out.

    I just need to work out the file attachment display. Id like it to just read "download" and the file would then begin to download on click.

    Ideas?

  3. MissDanni
    Member
    Posted 4 years ago #

    ok here we go

    For image:

    [thumbnail_id]
    type = file
    relation = true
    label = Upload your screenshot
    <?php
    $thumbnail_id = get_post_meta($post->ID, 'thumbnail_id', true);
    echo wp_get_attachment_image($thumbnail_id, 'thumbnail');
    ?>

    For file:

    [download]
    type = file
    relation = true
    label = Upload your theme
    <a href="<?php
    $download = get_post_meta($post->ID, 'download', true);
    echo wp_get_attachment_url($download);
    ?>">Download</a>

    Working wonderful now.

  4. aproimage
    Member
    Posted 4 years ago #

    Thanks for taking the time to round up your own question, I was starting to loose concentration after a long day and this was exactly what I was after, much appreciated!

    Rob

  5. Nilay
    Member
    Posted 4 years ago #

    Not getting it correctly. Where do I add <?php $thumbnail_id = get_post_meta($post->ID, 'thumbnail_id', true); echo wp_get_attachment_image($thumbnail_id, 'thumbnail'); ?>I added this in

    [cft] and [cftsearch] shortcode format
    with php enabled. Adding
    [cft format=0]
    in the post displays all other fields but not the image.

  6. Hiroaki Miyashita
    Member
    Posted 4 years ago #

    Hi Nilay,
    Before calling get_post_meta(), please add the following code:

    global $post;

    Probably it will work for you. Thanks.

  7. Nilay
    Member
    Posted 4 years ago #

    Works ! Thanks

  8. sperkDurkem
    Member
    Posted 4 years ago #

    Thank you, MissDanni, works great!

  9. Icethrill
    Member
    Posted 4 years ago #

    Has anyone noticed that everytime that you upload a file, and then choose delete on the checkbox. It automatically checks Uncategorized in the category field.

    This is really irritating... anyone know if you can fix this error/bug?

  10. Ahmad Bagadood
    Member
    Posted 4 years ago #

    I'm having the same issue.

    I have defined this custom field:

    [work_image]
    type = file
    relation = true

    and the format with PHP enabled is:

    <?php global $post;
    $work_image=get_post_meta($post->ID, 'work_image', true); ?>
    <div class="cft">
    <img src="/wp-content/uploads/<?php echo wp_get_attachment_url($work_image); ?>" width="730" alt="" />
    </div>

    But the function is not returning anything! So, the image is not displaying! Please help.

  11. proximity2008
    Member
    Posted 4 years ago #

    Tawqee3 that should work.

    Do a print_r on $post and see if it has the correct id for the function.

    Just before you call the get_post_meta function:

    print_r($post);

    Is the post id the one you are expecting for the get_post_meta function to pull the custom field?

  12. licinio
    Member
    Posted 3 years ago #

    Hi!

    Anyone can help me make the download butto0n a condition?

    What I mean is, I adapted this code for a file download, onlye there may not be a file...

    In which case I'd like for the download text not to appear...

    Something like...

    if there's a file show download link else show nothing

    My problem is translating this to php... :S

    Thanks in advance for any help!

  13. audioel
    Member
    Posted 3 years ago #

    Linicio - all you have to do is wrap an if statement around the button:

    <?php if($downloadlink = get_post_meta($post->ID, 'download_link', true)) { ?>
    
    <a href="<?php echo $downloadlink; ?>">Download</a>
    
    <?php }; ?>

    if you want it to do something else instead of just disappear, replace the last line with:

    <?php } else { ?>
    
    <b>Nothing to download here!</b>
    
    <?php }; ?>

Topic Closed

This topic has been closed to new replies.

About this Topic