This tutorial goes over how to create a custom template file to display our single downloads. This will allow us to create a custom look and feel for our digital products and not use the default single post layout/template.
Steps from the Video
- In your theme files duplicate
single.php
and name itsingle-download.php
- Duplicate
content-single.php
and save it ascontent-download.php
- In the template part of
single-download.php
make sure it is callingcontent-download.php
like the code below:
1<?php get_template_part( 'content', 'download' ); ?> - Remove the entry meta code from
content-download.php
, the template file should now look like:
1234567891011121314151617181920212223242526<?php/*** @package bootstrapwp*/?><article id="post-<?php the_ID(); ?>" <?php post_class(); ?>><header class="entry-header"><?php the_title( '<h1 class="entry-title">', '</h1>' ); ?></header><!-- .entry-header --><div class="entry-content"><?php the_content(); ?><?phpwp_link_pages( array('before' => '<div class="page-links">' . __( 'Pages:', 'bootstrapwp' ),'after' => '</div>',) );?></div><!-- .entry-content --><footer class="entry-footer"><?php edit_post_link( __( 'Edit', 'bootstrapwp' ), '<span class="edit-link btn btn-danger btn-xs">', '</span>' ); ?></footer><!-- .entry-footer --></article><!-- #post-## --> - In the
functions.php
file register a new sidebar with the following:
123456789register_sidebar( array('name' => __( 'Download', 'bootstrapwp' ),'id' => 'download','description' => '','before_widget' => '<aside id="%1$s" class="widget %2$s">','after_widget' => '</aside>','before_title' => '<h4 class="widget-title">','after_title' => '</h4>',) ); - Add the new downloads sidebar to the
single-download.php
file like the following:
1234567891011121314151617181920212223242526272829303132333435<?php/*** The Template for displaying all single downloads.** @package bootstrapwp*/get_header(); ?><div class="container"><div class="row"><div id="primary" class="col-lg-9 col-md-9"><main id="main" class="site-main" role="main"><?php while ( have_posts() ) : the_post(); ?><?php get_template_part( 'content', 'download' ); ?><?php /* bootstrapwp_post_nav(); */?><?php// If comments are open or we have at least one comment, load up the comment templateif ( comments_open() || '0' != get_comments_number() ) :comments_template();endif;?><?php endwhile; // end of the loop. ?></main><!-- #main --></div><!-- #primary --><?php get_sidebar('download'); ?><?php get_footer(); ?> - Create a new file in the root of your WordPress theme called
sidebar-download.php
. This file should look similar to the following:
12345678910111213141516171819<?php/*** The sidebar containing the download sidebar widget area.** @package bootstrapwp*/if ( ! is_active_sidebar( 'download' ) ) {return;}?><div id="secondary" class="widget-area col-md-3 col-lg-3" role="complementary"><?php dynamic_sidebar( 'download' ); ?></div><!-- #secondary --></div> <!-- .row --></div> <!-- .container --> - You should now have a widget area called Downloads in Appearance -> Widgets. Once you add widgets to this section, you will see them only on the download pages. Pretty neat!