WordPress.org

Support

Support » Themes and Templates » adding .php files to custom page

adding .php files to custom page

  • Hi!

    I’m building a custom page for my blog that will work as the main page. So I’ve added the <?php /* Template Name: something */?> to the top of the file.

    Can I import the different .php files from my theme folder. Say if I want to use the footer.php on my main page. Can I just add <?php get_footer(); ?> inside whatever div tag I want it in?

    Or is there something more I have to do?

Viewing 15 replies - 1 through 15 (of 22 total)
  • Yes. You can use whatever WordPress PHP functions you like.

    Cheers

    PAE

    Ok, that’s good. Then I must be missing something because I can’t see the footer when I put <?php get_footer(); ?> in the div footer tag.

    Any idea of what it can be?

    Cheers!

    Have you looked at what’s in the other page template files that form a part of your theme? The usual structure is something like:

    <?php get_header(); ?>
    
    <!-- Stuff that goes in the page body -->
    
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>

    The call to get_sidebar() is optional, of course, depending on whether the page requires the sidebar or not.

    HTH

    PAE

    Moderator Jose Castaneda

    @jcastaneda

    THEME COFFEE MONKEY

    Can you elaborate on what you mean that you can’t see the footer?

    yes, I’ve looked in the index.php to see how it’s done in there and from what I can see it should be enough with just putting <?php get_footer(); ?> in the appropriate place.

    What I mean with I can’t see the footer is that if I refresh the page in Firefox there’s just nothing showing where the footer ought to be.

    you can also try <?php include(‘footer.php’);?>

    Moderator Jose Castaneda

    @jcastaneda

    THEME COFFEE MONKEY

    Yeah, you can try using the PHP include method. I know it may sound so simple but there is a footer.php file in your theme directory? I know I’ve done that before where I forgot to put it in the right folder.

    Yes, I suppose that’s classic 🙂
    I’ve made my static page inside the TwentyEleven folder so every php-file for that theme should be available right?

    And also, I’m using a child theme .css file (child of twentyeleven’s style.css) but it doesn’t seem to find the CSS when I change it in wordpress to use my static page.
    I get the HTML of the static page but no CSS or JS. Has that happened to anyone?

    Why don’t you put your static page template inside your child theme folder? WordPress looks there first. Any files that are new in your child theme should be in the child theme folder, as should any template files that exist in your parent theme but that you want to edit.

    The usual procedure is to copy the original file from the parent theme folder to the child theme folder and then to edit the child theme version, leaving the parent theme version intact.

    When you create a child theme, nothing in your parent theme should change. This is essential when dealing with a default theme like twentyeleven.

    Cheers

    PAE

      On the CSS issue, have you included an @import statement in your child theme’s style.css file to include the parent theme’s style sheet?

      A minimal child theme (which is always the starting point when developing a child theme) comprises:

    • A folder in wp-content/themes
    • A CSS file in that folder, called style.css, and containing:
    • The mandatory comments at the top of the page
    • An @import statement to import the parent theme’s stylesheet

    Cheers

    PAE

    ok, I’ve put all my files in my child theme folder and a copy of the original footer.

    I am still not getting any result when I try to include the footer on the page tho.
    I’ve tried both <?php get_footer(); ?> and <?php include(“footer.php”); ?>
    but nothing happens.
    I must be missing something else.

    Well, you shouldn’t need a copy of the original footer, unless you intend to change it. Maybe that’s what’s in your mind…

    When WP uses a child theme, it looks for a stylesheet in the child folder. That’s why the child style sheet is mandatory. It then looks for any template files first in the child theme and then in the parent. So any template files that haven’t changed can just be left where they are, in the parent.

    Basically the child theme just contains the differences between the child and the parent.

    So let’s get back to basics:

    • Does your child theme appear in the list of available themes in the Dashboard?
    • Assuming it does, have you successfully activated it, such that it shows up in the Dashboard as the active theme?
    • Assuming it does, when you go to Dashboard –> Appearance –> Editor do you see your child theme’s style sheet open in the editor and do you see links to all your child theme’s template files in the list on the right?
    • Do the files available in the editor all contain the code you expect?

    If all that’s OK we can try to move on.

    Is there no way you can post a link to your site so we can see what’s going on?

    Cheers

    PAe

    Yes, all the expected files are listed on the menu to the left in the editor. I’ve made a seperate .css file for the Home Page Template that imports the child theme. and they’re all in the child theme folder.

    If I go to settings -> reading and choose static page and my Home Page template then it works but there’s no CSS or JS. If I open up Firebug it says that there are no css rules applied so for some reason it’s not being read.

    If I use the default “Your latest post” option in Settings -> Reading them the CSS works for the blog. So the child theme is working. It’s only when I try to use the Home Page template and it’s corresponding css-file.

    I’m still just getting started with developing wordpress sites so
    thanks for taking the time and helping btw!

    Cheers!

    It’s not finding your style sheet. You need to check the relative path in your child theme’s @import statement, although, to be honest I don’t see why you need a separate child sheet.

    If you’ve put code directly into your HTML page to get the special style sheet, you need to use an absolute URL or the style sheet will never be found. So in your template file you need something like:

    ...
    <link rel="stylesheet" type="text/css" href="<?php bloginfo('stylesheet_directory'); ?>/my_special_styles.css" />
    ...

    This assumes that your special style sheet is in the same directory as your theme’s style sheet. If not, you need to adjust the path.

    HTH

    PAE

    So it might be better to just stick with the one child theme css file?

Viewing 15 replies - 1 through 15 (of 22 total)
  • The topic ‘adding .php files to custom page’ is closed to new replies.
Skip to toolbar