Support » Fixing WordPress » get template part not working

  • Resolved emaarkhan


    i came across this function of get_template_part and i think its awesome for reuse of code. but i am using it with my new theme and its not loading.i named my file about-template.php, when i load it using get_template_part('about','template'); it doesn’t seem to work. am i doing something wrong?

Viewing 15 replies - 1 through 15 (of 16 total)
  • Please reread

    The first parameter in your get_template_part() function has to refer to a generic file. About.php isn’t a generic file.

    generic , how? i am not getting that part from codex

    Do you have an about.php file? That should be the generic.
    To call about.php, use get_template_part(‘about’);

    I do, but i want the files like about-template.php, services-template to be called in get template part. but how



    Forum Moderator

    when i load it using get_template_part('about','template'); it doesn’t seem to work

    where exactly are you using that code?
    in which location is about-template.php?
    what output are you expecting?

    it worked in my test installation using the line in the default page.php template (Twenty Twelve child theme; file located at /wp-content/themes/tentytwelvechild/about-template.php; contained a simple line with a php echo),
    and also worked with this variation:

    <?php get_template_part(‘about-template’);?>
    using it in index.php
    for now i m just checking with echo
    wht i expect in junk of code that will be inserted if page about is loaded.

    If you use get_template_part(‘about’,’template’);, then you’re telling wordpress there is a template file called ‘about.php’ but here, I want to use about-template.php but, just in case about-template.php isn’t available, go ahead and use about.php.

    The hyphen in your template file names has meaning, so watch out.

    i think i do understand what ur saying, still its not loading. here is my page and here is about-template which only say echo hello world. what am i missing?

    Edit: not even the page is outputting its the_title and stuff 🙁

    Ok, let’s do it simpler.

    Do you have an about.php file, yes or no?


    Ok, then calling this: get_template_part(‘about-template’); will get the content of the about-template.php file.

    If not.
    Make a new file in your theme folder.
    Call it abouttest.php.
    Put one line inside it:
    <p>This is the content of abouttest.php</p>
    Call this template file: get_template_part(‘abouttest’);

    seeing through ur example. i saw my mistake, i was putting .php in the file. now its working! thnx!

    i see my the_content isn’t working in that page. the one i pasted the link above. even after putting in the loop

    yes seen that, but it doesn’t seem to work

Viewing 15 replies - 1 through 15 (of 16 total)
  • The topic ‘get template part not working’ is closed to new replies.