0

I'm writing my first twenty twelve child theme and came across (what I think) is a strange quirk.

I modified front-page.php to have a slider using sliderjs, afterwards I decided I did not want to use this as a front page template, so I'd much prefer to call it something else for a different page.

To my surprise, the moment I renamed front-page.php to text-carousel.php and changed the Template Name in the docblock to something else the page changes from displaying my content in full width and the widgets below to a 2 column version similar to my blog, but with the widgets assigned to front-page.

So, is front-page.php a reserved template in twenty twelve? is it possible to duplicate its look and feel into a different template?

For reference here's my code:

<?php
/**
 * Template Name: Text Carousel Page Template
 *
 * Description: A page template that provides a key component of WordPress as a CMS
 * by meeting the need for a carefully crafted introductory page. The front page template
 * in Twenty Twelve consists of a page content area for adding text, images, video --
 * anything you'd like -- followed by front-page-only widgets in one or two columns.
 *
 * @package WordPress
 * @subpackage Twenty_Twelve
 * @since Twenty Twelve 1.0
 */

get_header('nonav'); ?>

<div id="primary" class="site-content">
    <div id="content" role="main">
        <div id="example">
            <div id="slides">
                <div class="slides_container">
        <?php 
        $args = array(
                        'posts_per_page'  => 5,
                        'orderby'         => 'post_date',
                        'order'           => 'DESC',
                        'post_type'       => 'post',
                        'post_status'     => 'publish',
                        'suppress_filters' => true );

                    $myposts = get_posts( $args );
                    foreach( $myposts as $post ) :  setup_postdata($post); ?>
                        <div class="slide">
                          <h2><?php the_title(); ?></h2>
                          <p><?php echo get_the_excerpt(); ?></p>
                          <p><a href="<?php the_permalink(); ?>" class="link">Leer articulo</a></p>
                        </div>
                    <?php endforeach; ?>
                </div><!-- .slides_container -->
            </div><!-- #slides -->
        </div><!-- #example -->

    </div><!-- #content -->
</div><!-- #primary -->
<?php get_sidebar( 'front' ); ?>
<?php get_footer(); ?>

It works fine if the file is called twentytwelve/page-templates/front-page.php with Template Name: Template Name: Front Page Template, but it goes 2 column as twentytwelve/page-templates/text-carousel.php with Template Name: Text Carousel Page Template

I had posted this question in stackoverflow, but it didn't seem to be getting too much success so I decided to open an account here and move it across.

3
  • 1
    It is not done to post your question on multiple SE sites. Please remove it here or there. You could also have asked a moderator to migrate your question, which would've been the best.
    – user26607
    Commented Mar 8, 2013 at 15:25
  • Wow... you posted on Stack Overflow about 20 minutes before you posted here.
    – s_ha_dum
    Commented Mar 8, 2013 at 15:42
  • I thought I had deleted that one, I moved it across because I figured this site is more in line with the subject.
    – rantsh
    Commented Mar 8, 2013 at 16:31

3 Answers 3

0

I had the exact same problem and finally figured it out. You have to go into functions.php line 390 -

if ( is_page_template( 'page-templates/front-page.php' ) ) {

copy and paste this section of code and rename it to the file name you have chosen for your template.

Then you have to alter all the CSS that references .template-front-page to whatever you called your template. (I made it easy and just added to the file name - you could call it template-front-page-carousel for example)

A little tweaking here and there and two identical templates - no you can change the content to your needs.

1

Wordpress includes a class to the page template in the <body> tag of the page. If you know how to use CSS you can just style the template to look exactly like the front-page.php by using this class. The class would look something like .page-template-text-carousel-page-template-php.

It wouldn't take very long to add some styles to change the layout to whatever you like.

3
  • 1
    Refer to style.css. The section is /* =Front page template */, and the CSS selector is the .template-front-page body class. Commented Mar 8, 2013 at 16:48
  • There you go just copy those styles for your page template and your done. Thanks Chip Commented Mar 8, 2013 at 17:00
  • @ChipBennett this is exactly what I was looking for. Thank you
    – rantsh
    Commented Mar 8, 2013 at 19:03
0

front-page.php is a reserved template in WordPress, not just Twenty Twelve. The templating system is implemented and enforced by the WordPress core not by any particular theme.

http://codex.wordpress.org/Theme_Development#Template_Files_List

3
  • So how can I get a page that overall gets the same style as this one, but with customized content different from front-page.php?
    – rantsh
    Commented Mar 8, 2013 at 15:19
  • With a custom template, you need to create a page from the backend and assign that page to the template. Did you do that?
    – s_ha_dum
    Commented Mar 8, 2013 at 15:55
  • yes, when I assign it the front-page template it looks great, as soon as I assign it to the other template (which is a clone of the front page template with a diff name) it creates a sidebar with the widgets instead of keeping them at the bottom
    – rantsh
    Commented Mar 8, 2013 at 16:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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