Title: Custom Template success
Last modified: February 18, 2019

---

# Custom Template success

 *  [rboatright](https://wordpress.org/support/users/rboatright/)
 * (@rboatright)
 * [7 years, 6 months ago](https://wordpress.org/support/topic/custom-template-success/)
 * We have recently redesigned our magazine site which uses the Issuem plugin to
   manage magazine issues.
 * We provide downloadable E copys of each issue to subscribers in several formats…
   epub, mobi, html-zip, etc. We store those in DLM as versions. We wanted the download
   page to show the issuem cover image for each issue, along with the versions, 
   without requiring our editorial staff to re-connect the image to that issues 
   downloads.
 * You can see an image of the resulting download archive page at [https://grantvillegazette.com/wp/wp-content/uploads/2019/02/DLM_page.png](https://grantvillegazette.com/wp/wp-content/uploads/2019/02/DLM_page.png)
   We’re pretty proud of it.
 * The template is in our theme’s child-theme in a download-monitor directory as
   download-content-fancy and is called with a shortcode [downloads loop_start='
   <div class=dlm_custom_shortcode>’ loop_end='</div>’ before='<span>’ after='</
   span>’ orderby=title order=DESC template=fancy]
 * Figuring this out was not trivial. DLM’s documentation of custom templates, and
   of the various functions inside DLM is not rich, however this sort of thing is
   possible.
 * It’s certainly true that the code in the template could be improved on, it’s 
   pretty much a hack, but there are so few posts in this forum about successes 
   that I thought it would be good to share one.
 * So, with excuses about quality etc. here’s the code.
 *     ```
       <?php
   
       if (!defined('ABSPATH')) {
           exit;
       } 
   
       /** @var DLM_Download $dlm_download */
       $dlTitle = $dlm_download->get_title();
       $mySlug = 'gg-0' . str_ireplace('Grantville Gazette Volume ','',$dlTitle);
   
       echo '<div id="' . $mySlug . '" class="dlm_custom_download"><p>';
   
       $issueArgs = array(
           'taxonomy'  => 'issuem_issue',
           'slug'      => $mySlug,
       );
       $theseIssues = new WP_Term_Query($issueArgs);
   
       foreach ($theseIssues->terms as $thisIssue) {
               $issue_meta = get_option( 'issuem_issue_' . $thisIssue->term_id . '_meta' );
               $myCover = wp_get_attachment_image_src( $issue_meta['cover_image'], array(138, 220,));  
               echo '<img class="attachment-issuem-cover-image size-issuem-cover-image" alt="Cover for '. $mySlug . '-" src="' . $myCover[0] . '"><br>';
               echo str_ireplace('Grantville Gazette ','',$dlTitle) . "<br></p>";
           }
   
       $versions = $dlm_download->get_versions();
   
       if ( count( $versions ) < 1 ) {
       	echo 'No versions found.';
       } else {
   
       		foreach ( $versions as $version ) {
       			// get the versions meta-data into a variable 
       			$thisVersion = $dlm_download->get_version( $version );
   
       			// now, build a NEW array we can sort on the version number (rtf, html, epub, mobi)
       			// consisting of key->value pairs of version_number->downloadURL 
       			$versionList[$version->get_version_number()] = $dlm_download->get_the_download_link(array( version => $thisVersion, )) ;
       		} 
   
       		// now, sort that new array by its keys, so it goes into consistent order. 
       		ksort($versionList);
   
       		// now, loop through the sorted array and build the links to each version 
       	    while ($dlLink = current($versionList)) {
                   echo ' <a class="download-link" href="' . $dlLink  . '?version=' . key($versionList) . '" rel="nofollow">';
       			echo key($versionList)  . '</a> ';
       		    next($versionList);
       		}
       		echo '</div>'; 
       }
       ```
   

The topic ‘Custom Template success’ is closed to new replies.

 * ![](https://ps.w.org/download-monitor/assets/icon-256x256.png?rev=3198936)
 * [Download Monitor](https://wordpress.org/plugins/download-monitor/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/download-monitor/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/download-monitor/)
 * [Active Topics](https://wordpress.org/support/plugin/download-monitor/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/download-monitor/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/download-monitor/reviews/)

## Tags

 * [custom](https://wordpress.org/support/topic-tag/custom/)
 * [DLM](https://wordpress.org/support/topic-tag/dlm/)
 * [template](https://wordpress.org/support/topic-tag/template/)
 * [[Success]](https://wordpress.org/support/topic-tag/success/)

 * 0 replies
 * 1 participant
 * Last reply from: [rboatright](https://wordpress.org/support/users/rboatright/)
 * Last activity: [7 years, 6 months ago](https://wordpress.org/support/topic/custom-template-success/)
 * Status: not a support question