Support » Themes and Templates » WP functions (get_header, etc.) not working

  • CuriousLittleBird

    (@curiouslittlebird)


    I’ve been trying to build my own theme for my blog, Crooked Glasses, and the theme I’ve got cobbled together right now works as long as I don’t put any WP functions in (like get_header, wp_list_pages, etc.). As soon as I put something like the following code in my page, I get a “Fatal error: Call to undefined function” error:

    <?php wp_list_pages() ?>
    <?php get_header() ?>

    I’ve had to call the header with a relative filepath instead, which apparently means that the header only works on the main page (index.php). As soon as you click off onto FAQ, About Me, Links, or even Previous Entries, it turns the page into an ugly text-only display.

    I kinda have a grasp on how to build the theme, but it certainly is a setback to not have any of the dynamic content like wp_list_pages and wp_most_recent_posts (I think that’s right), and not to be able to have my layout visible past the first page. I have no idea what I’m doing wrong–I’ve tried to put in the code exactly as all these guides and tutorials have shown me.

    Odd footnote to this: The Loop’s functions work wonderfully–stuff like “while (have_posts); the_post;”, “the_time”, “the_date”, etc. Any WP functions outside the Loop breaks the whole page. I am a relative newb to PHP, so most of my “troubleshooting” just leads to more confusion.

Viewing 7 replies - 1 through 7 (of 7 total)
  • wpexplorer

    (@wpexplorer)

    As a general rule make sure to always have the ending ; in your functions. Such as;

    <?php get_header(”); ?>
    <?php wp_list_pages(”); ?>

    Thread Starter CuriousLittleBird

    (@curiouslittlebird)

    Wow, can’t believe I forgot the semicolons. Shows what writing while suffering a massive migraine results in! XD

    I tried editing the “Main Index.php Template” through the Theme Editor thing, and it seemed successful, but it still didn’t fix the issue of the layout not displaying past the main page. Then, I tried uploading the index.php file into the main subdirectory, resulting in this lovely error message:

    Fatal error: Call to undefined function get_header() in /home/withinm/public_html/glasses/index.php on line 1

    I did type the semicolons this time, so I’m not sure what’s wrong. Here are the first two lines of my index.php file (the get_header version that renders the “Fatal Error”):

    <?php define('WP_USE_THEMES', false); get_header(); ?>
    <?php include('./wp-blog-header.php'); ?>

    And here is the include path that works:

    <?php define('WP_USE_THEMES', false); include('./wp-content/themes/glasses/header.php'); ?>
    <?php include('./wp-blog-header.php'); ?>

    I’ve also noticed that I have one index.php file in my main subdirectory and one index.php file in my theme’s folder. Is this how it’s supposed to be, or is one of them supposed to be deleted?

    Chip Bennett

    (@chipbennett)

    This is wrong:

    /home/withinm/public_html/glasses/index.php

    Your Theme should be here:

    /home/withinm/public_html/wp-content/themes/glasses/

    And your index.php file here:

    /home/withinm/public_html/wp-content/themes/glasses/index.php

    Chip Bennett

    (@chipbennett)

    If you are editing the index.php file in your WordPress root install directory, stop! Don’t do that!

    If you have edited that file, restore it to its original.

    Thread Starter CuriousLittleBird

    (@curiouslittlebird)

    @chip: Had no idea I wasn’t supposed to edit the root install’s index.php file. Where would I find the original copy? Hope I don’t have to reinstall WP because of an error of ignorance. :S

    (All these similarly-named files in various locations are very confusing for a WP newb! LOL!)

    esmi

    (@esmi)

    Where would I find the original copy?

    http://wordpress.org/download/

    And you might want to look over Theme_Development.

    Thread Starter CuriousLittleBird

    (@curiouslittlebird)

    Well, after being utterly without internet for several days, I can finally reply! 🙂

    My sincere thanks to esmi and Chip Bennett for helping me clear up one mystery in my WP odyssey. I uploaded the original index.php file to the root directory. Apparently, this fix plus a random fiddle on my part managed to get the get_header, get_sidebar, and get_footer to work. (I changed ‘false’ to ‘true’ in <?php define(‘WP_USE_THEMES’, false;) ?> at the very top of my personal index.php file.) I’ve also attempted using some other WP functions, with very limited success, so I will keep trying.

    However, I’m still having problems with the layout not displaying beyond the first page of the site. Clicking “Previous Entries”, any of the category links, or any of the Pages results in ugly text-only display. I know the header.php file (the file with most of my layout code) is being called, because the alt text for the image is the first text on the page. What could be going on?

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘WP functions (get_header, etc.) not working’ is closed to new replies.