Support » Themes and Templates » Child theme page.php override

  • Resolved crmunro

    (@crmunro)


    Hello,

    Firstly, would I be right in thinking that page.php is the “default template” for WordPress pages?

    If so, how can I change the default template? I’m using the twentyeleven theme with a child theme added to it, and want to change the default page template to one with a sidebar.

    Thankyou in advance for any help you can provide!

Viewing 5 replies - 1 through 5 (of 5 total)
  • Copy the page.php file into your child theme’s directory –

    add this:

    <?php get_sidebar(); ?>

    above this:

    <?php get_footer(); ?>

    And you should have your sidebar.

    Thread Starter crmunro

    (@crmunro)

    david.bailey – thankyou for your suggestion, but unfortunately it does not work, though I’m not sure why.
    After doing what you said, the sidebar appears – but at the bottom of the page, unaligned with the main content.
    I compared sidebar-page.php and page.php with each other, and they are exactly the same… And yet sidebar-page.php works perfectly.

    You’ll need to modify the CSS accordingly, to accommodate the layout change you’re introducing (from a one-column layout to a two-column layout). Twenty Eleven is a fixed-width Theme, so you’ll need to reduce the width of the content area in order to accommodate the sidebar column width.

    Chip beat me to it – at this point, if it’s showing up in the theme and it’s not appearing where you want it to, you’ll just need to do some styling to modify its position.

    Thread Starter crmunro

    (@crmunro)

    Hiya guys,

    thankyou for your replies. I could see what you were saying, but would require a lot of legwork and mean that I could not have on individual page with no sidebar (I think..)

    Anyway, I did some digging through functions.php and found, a few lines from the end:

    if ( is_singular() && ! is_home() && ! is_page_template( 'showcase.php' ) && ! is_page_template( 'sidebar-page.php' ) )
    		$classes[] = 'singular';

    this set me in the right direction, however when I tried redeclaring that line, including single pages/page.php, I got a bunch of scary “fatal errors”.

    I just found Someone else’s child theme to fix this issue (from this thread). Incorporated those functions and two pages into my child theme, works like a dream. Turns out you need to declare the single.php file, but under a different function.

    Thankyou all once more for your help!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Child theme page.php override’ is closed to new replies.