WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] get template part not working (17 posts)

  1. emaarkhan
    Member
    Posted 1 year ago #

    hi,
    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?

  2. Peter_L
    Member
    Posted 1 year ago #

    Please reread http://codex.wordpress.org/Function_Reference/get_template_part

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

  3. emaarkhan
    Member
    Posted 1 year ago #

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

  4. Peter_L
    Member
    Posted 1 year ago #

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

  5. emaarkhan
    Member
    Posted 1 year ago #

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

  6. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    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:
    get_template_part('about-template');
    .

  7. emaarkhan
    Member
    Posted 1 year ago #

    using
    <?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.

  8. Peter_L
    Member
    Posted 1 year ago #

    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.

  9. emaarkhan
    Member
    Posted 1 year ago #

    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 :(

  10. Peter_L
    Member
    Posted 1 year ago #

    Ok, let's do it simpler.

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

  11. emaarkhan
    Member
    Posted 1 year ago #

    no

  12. Peter_L
    Member
    Posted 1 year ago #

    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');

  13. emaarkhan
    Member
    Posted 1 year ago #

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

  14. emaarkhan
    Member
    Posted 1 year ago #

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

  15. Peter_L
    Member
    Posted 1 year ago #

  16. emaarkhan
    Member
    Posted 1 year ago #

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

  17. emaarkhan
    Member
    Posted 1 year ago #

    I figured it out, thanks guys!

Topic Closed

This topic has been closed to new replies.

About this Topic