• 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 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.