• Resolved Rose

    (@eos-rose)


    Each of my posts has a download id saved to the custom field mp3_id. For various reasons, using a shortcode to display the link and metadata for this download is impossible. I need to hook into the download information directly from my single.php template. How do I do this?

    This is the only code I found:

    $dl = get_downloads('limit=5&orderby=hits&order=desc');
    if (!empty($dl)) {
    echo '<ul>';
    foreach($dl as $d) {
    echo '<li><a href="'.$d->url.'" title="Version '.$d->version.' downloaded '.$d->hits.' times" >'.$d->title.' ('.$d->hits.')</a></li>';
    }
    echo '</ul>';
    }

    Since I’m not looking to create a loop of any kind, just access the information for a specific download from my single post template, this code is useless to me.

    http://wordpress.org/extend/plugins/download-monitor/

Viewing 1 replies (of 1 total)
  • Thread Starter Rose

    (@eos-rose)

    For those of you interested, I created the following function to display my downloads without a shortcode:

    if(!function_exists('download')){
    	function download(){
    		global $post;
    		global $wpdb;
    		if(get_post_meta($post->ID, 'mp3_id', true)) {
    			$mp3_id = get_post_meta($post->ID, 'mp3_id', true);
    			$format = $wpdb->get_var("SELECT meta_value FROM wp_download_monitor_file_meta WHERE meta_name = 'format' AND download_id = $mp3_id ORDER BY ID DESC LIMIT 0 , 1");
    			$filesize = $wpdb->get_var("SELECT meta_value FROM wp_download_monitor_file_meta WHERE meta_name = 'filesize' AND download_id = $mp3_id ORDER BY ID DESC LIMIT 0 , 1");
    			$duration = $wpdb->get_var("SELECT meta_value FROM wp_download_monitor_file_meta WHERE meta_name = 'duration' AND download_id = $mp3_id ORDER BY ID DESC LIMIT 0 , 1");
    
    			return '<li><a href="http://mywebsite.com/download/' . $mp3_id . '">' . $format . '</a> | <b>Size:</b> ' . $filesize . ' | <b>Duration:</b> ' . $duration . '</li>' . "\n";
    		}
    	}
    }

    This takes the Download ID that I’ve included in the custom fields of various posts and displays the download in my post template wherever I insert <?php echo download(); ?>.

    JournalPress doesn’t spit this code back out at me like it does shortcodes! It’s too bad I can’t determine how to include the assigned permalink as a variable, but I’ve been using id-based links all along, so it works out fine for me. If anyone does figure out how to snag the Download Monitor permalink without shortcodes, please let me know!

Viewing 1 replies (of 1 total)
  • The topic ‘[Plugin: WordPress Download Monitor] Add download template to single.php?’ is closed to new replies.