- This topic has 4 replies, 2 voices, and was last updated 8 years, 11 months ago by Chris.
-
AuthorPosts
-
18 April 2015 at 17:49 #6400ChrisParticipant
Hello, first this is a great plugin and thanks for it.
I am creating a download section on my site. It has a list format below the image and in the list it shows the author, date added, tags, and category for each image. I was wondering if I could pull some the info that your plugin pulls (individually) into my list? Like the file size and download count. Pull it from your code and add it to my list etc.. Then just have a button by itself that says download.
Thank you
Chris18 April 2015 at 19:05 #6401BartoszKeymasterHmm, looks like there is no simple method for for doing this per single attachment. But it should be there :)
So please try the function below. All you need to get the data is the attachment_id, which should be accessible per attaachment, in your download section. This function will be included in DA after the next plugin update as well:
/** * Get single attachment download data * * @param int $attachment_id * @return array */ function da_get_download_attachment($attachment_id = 0) { $attachment_id = !empty($attachment_id) ? absint($attachment_id) : 0; // break if there's no attachment ID given if(empty($attachment_id)) return false; // break if given ID is not for attachment if(get_post_type($attachment_id) != 'attachment') return false; $options = get_option('download_attachments_general'); $file = get_post($attachment_id); $filename = get_attached_file($attachment_id); $filetype = wp_check_filetype($filename); $extension = ($filetype['ext'] === 'jpeg' ? 'jpg' : $filetype['ext']); $attachment['title'] = get_the_title($attachment_id); $attachment['caption'] = trim(esc_attr($file->post_excerpt)); $attachment['description'] = trim(esc_attr($file->post_content)); $attachment['date'] = date_i18n(get_option('date_format').' '.get_option('time_format'), strtotime($file->post_date)); $attachment['size'] = size_format((file_exists($filename) ? filesize($filename) : 0)); $attachment['type'] = $extension; $attachment['downloads'] = (int)get_post_meta($attachment_id, '_da_downloads', true); $attachment['url'] = ($options['pretty_urls'] === true ? site_url('/'.$options['download_link'].'/'.$attachment_id.'/') : plugins_url('download-attachments/includes/download.php?id='.$attachment_id)); $attachment['icon_url'] = (file_exists(DOWNLOAD_ATTACHMENTS_PATH.'images/ext/'.$extension.'.gif') ? DOWNLOAD_ATTACHMENTS_URL.'/images/ext/'.$extension.'.gif' : DOWNLOAD_ATTACHMENTS_URL.'//cdn.dfactory.co/images/ext/unknown.gif'); return apply_filters('da_get_download_attachment', $attachment, $attachment_id); }
18 April 2015 at 19:23 #6402ChrisParticipantI am sorry I meant to say it isn’t for just one file. It will be done for every file I upload and share on my site. I am looking at the function now trying to figure it out.
Thank you. Been out of php to long and very rusty now. LOL
Here is a screenshot of what I am trying to do.
18 April 2015 at 19:29 #6403BartoszKeymasterYes, I understand that.
This function should be very flexible and work for you, no matter if you have on or more attachments. It will return an array of attachment data, fot the given attachment ID, but can be used in a loop (like a list of images for example).
Just experiment with it for a while :)
18 April 2015 at 19:37 #6404ChrisParticipantThanks again. I will mess around and see what I can do either good or bad :)
-
AuthorPosts
- You must be logged in to reply to this topic.
How to Get Support
After you register and login to the site, you may post all plugin support questions in the Support Forum.
If you need to provide private info, please create a ticket and then reply to it using Set as private reply option.
Sign Up
Please login or sign up for a free account.Sign Up Now