• Hi – I was reading up on templates and so far I have successfully created my own page template that appears in the template dropdown menu when editing a page. However I want to pre-populate the template with some data. So I created an html file that I wanted to include into the custom template php file using the include statement (include(‘bd-template-content.html’);). The problem is that html content does not appear when I create a new page and use the custom template. The bd-template-content.html file is simply a cut and paste from the text of an existing page which I know works.

    Below is the example code that is in the php file and shows where I’ve included the ‘include statement just before the end of the content div.

    Any advice would be most welcome

    Simon

    <?php/*Template Name: Birdanddine*/ ?>
    get_header(); ?>

    <div id=”content” class=”<?php echo esc_attr( implode( ‘ ‘, responsive_get_content_classes() ) ); ?>”>

    <?php if ( have_posts() ) : ?>

    <?php while( have_posts() ) : the_post(); ?>

    <?php get_template_part( ‘loop-header’, get_post_type() ); ?>

    <?php responsive_entry_before(); ?>
    <div id=”post-<?php the_ID(); ?>” <?php post_class(); ?>>
    <?php responsive_entry_top(); ?>

    <?php get_template_part( ‘post-meta’, get_post_type() ); ?>

    <div class=”post-entry”>
    <?php the_content( __( ‘Read more ›’, ‘responsive’ ) ); ?>
    <?php wp_link_pages( array( ‘before’ => ‘<div class=”pagination”>’ . __( ‘Pages:’, ‘responsive’ ), ‘after’ => ‘</div>’ ) ); ?>
    </div><!– end of .post-entry –>

    <?php get_template_part( ‘post-data’, get_post_type() ); ?>

    <?php responsive_entry_bottom(); ?>
    </div><!– end of #post-<?php the_ID(); ?> –>
    <?php responsive_entry_after(); ?>

    <?php responsive_comments_before(); ?>
    <?php comments_template( ”, true ); ?>
    <?php responsive_comments_after(); ?>

    <?php
    endwhile;

    get_template_part( ‘loop-nav’, get_post_type() );

    else :

    get_template_part( ‘loop-no-posts’, get_post_type() );

    endif;
    include(‘bd-template-content.html’);
    ?>
    </div><!– end of #content –>

    <?php get_sidebar(); ?>
    <?php get_footer(); ?>

  • The topic ‘How to prepopulate a custom template’ is closed to new replies.