Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #6400
    Chris
    Participant

    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
    Chris

    #6401
    Bartosz
    Keymaster

    Hmm, 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);
    }
    #6402
    Chris
    Participant

    I 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.
    screenshot

    #6403
    Bartosz
    Keymaster

    Yes, 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 :)

    #6404
    Chris
    Participant

    Thanks again. I will mess around and see what I can do either good or bad :)

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.