• I just upgraded to 2.8 and not sure how to create a custom page template. Specifically, I don’t want the comment form on my pages.

    How do I customize my Pages in 2.8?

    Thanks.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Custom page templates are created using the same basic approach as in previous versions:

    http://codex.wordpress.org/Pages#Page_Templates

    If you just want to remove comment links and comment forms from your current templates, see http://quirm.net/2009/06/16/removing-all-reference-to-wordpress-comments/.

    Thread Starter deko

    (@deko)

    Thanks esmi. The codex article wasn’t very clear, but I figured it out. You just create a php file in your theme directory (e.g. /public_html/my-blog-name/wp-content/themes/my-theme-name/page-custom.php) and define the name of the page template in the top of the php file like so:

    <?php
    /*
    Template Name: my-custom-page
    */
    ?>

    Afterwards, you will see a Template section with dropdown list when you go to Add a New Page. If no custom templates are defined, that section and the dropdown list is not there, which makes it confusing.

    Thread Starter deko

    (@deko)

    One thing I’m still not sure about is how to insert custom javascript into the header of my custom Page Template. I know I can call a .js file that contains my script, but I think that means editing the header.php file of my theme–and that will impact everything, not just the custom Page.

    Is there anyway to include custom javascript in a custom Page Template?

    Not necessarily. You could include it in your header.php file but using the is_page_template() conditional.

    <?php if(is_page_template('custom_page.php')) :?>
    <script src="<?php bloginfo('template_directory'); ?>/custom_script.js" type="text/javascript"></script>
    <?php endif;?>
    Thread Starter deko

    (@deko)

    It sounds like is_page_template() should do it.

    I’m still a little mystified over how Default and Custom Templates work, however.

    I’ve renamed the page.php file in my theme directory to custom_page.php and added the appropriate php comments at the top of the file (I called it ‘Custom Template’). Now I can see ‘Custom Template’ in the drop-down menu when I Add New Page–but I also see ‘Default Template’. Where did this ‘Default Template’ come from?

    It looks like this ‘Default Template’ simply uses index.php, which inserts the_content of the Page as well as the comments_template, sidebar and footer. I assume I can use is_page_template() to customize (or omit) each of these components as needed.

    Since I want all my Pages customized the same way, couldn’t I just use is_page_template('Default Template') in each component file of my theme to effect my Page customizations? Why bother with a custom Page template?

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Custom Page Templates?’ is closed to new replies.