I'm creating a new Page Template.

I want to change margins, fonts, font sizes, and things like that.

I don't know if I've done things right. Is the following process that I've followed sound?:

  1. I created a new file 'salespagetemplate.php' and placed this in the active theme (twentyeleven-child).

  2. In the file 'salespagetemplate.php', I have the following code, and only this code:

     * Template Name: Salespage
    wp_enqueue_style( 'my-page-template', get_template_directory_uri() . '/css/page-template.css' );
    <div id="primary">
        <div id="contentwide" role="main">
            <?php the_post(); ?>
            <?php get_template_part( 'content', 'page' ); ?>
        </div><!-- #content -->
    </div><!-- #primary -->

(some of that code isn't appearing in this post -- don't know how to make it appear.)

  1. I created a new file 'page-template.css', which is referred to in the code above, and which if I understand correctly, I can edit to change css for the page template.

And, in case I'm supposed to be referencing any of the existing files and am doing so incorrectly, here is the list of file names I have in the active theme folder:

content.php functions.php page.php salespagetemplate.php single.php style.css page-template.css

  • 1
    Dude, you can see the URL is /css/page-template.css, so either put it in the subfolder css, or change the path! You really should have continued the convo on your original Q rather than posting a new one. – TheDeadMedic Jul 31 '12 at 22:23
  • And since this is a child theme, use get_stylesheet_directory_uri() instead ;) – TheDeadMedic Jul 31 '12 at 22:25
  • 1
    And after posting an answer, I see that this really is a duplicate question. – Chip Bennett Jul 31 '12 at 22:25

A page template defines the full rendered content displayed: header, footer, content - everything. So, at the very least, you'll need to call get_header() and get_footer(), or manually add the header and footer code to the template.

Also, I would recommend using a callback to enqueue your custom stylesheet. You can use the is_page_template() conditional to check for your specific page. For example:

function wpse60383_enqueue_custom_style() {
    if ( is_page_template( 'salespagetemplate.php' ) ) {
        wp_enqueue_style( 'my-page-template', get_template_directory_uri() . '/css/page-template.css' ); 
add_action( 'wp_enqueue_scripts', 'wpse60383_enqueue_custom_style' );

Note: this callback and hook goes in your functions.php file.

| improve this answer | |

Child theme is the way to go.


"style.css is the one and only required file in a child theme. It provides the information header by which WordPress recognizes the child theme, and it replaces the style.css of the parent."

Template Files

Templates in a child theme behave just like style.css, in that they override their namesakes from the parent. A child theme can override any parental template by simply using a file with the same name. (NOTE. index.php can be overriden only in WordPress 3.0 and newer.)

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.