[Plugin: Custom Field Template] File and Image Display
-
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.
-
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?
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.
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
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.
Hi Nilay,
Before calling get_post_meta(), please add the following code:global $post;
Probably it will work for you. Thanks.
Works ! Thanks
Thank you, MissDanni, works great!
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?
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.
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?
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!
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 }; ?>
- The topic ‘[Plugin: Custom Field Template] File and Image Display’ is closed to new replies.