Support » Themes and Templates » get_template_part


  • I’m trying to use the get_template_part to rehuse the loop for single post pages, but the documentation is not clear, to me at least.

    I need to use the same html structure in the single page/post and home templates and another file for multiple-post templates, and I need to know how to name them and how to call them with this function.

    The documentation says:

    (string) (optional) The name of the specialized template.

    I don’t know what “the specialized template” means. Is that the kind of pages it will applied to? Is that the template “type” that will be opened when used this function regardless of the kind of template it has been called from? or the template name it will look for?

    My theme doesn’t have any child. I’m building it from scratch.

    Can anybody give me, at least, a few more examples for me to figure it out, or just expand the above definition

Viewing 6 replies - 1 through 6 (of 6 total)
  • esmi


    Forum Moderator

    The optional name refers to the suffix that is added to template file names when creating custom templates. Eg:

    get_template_part('loop', 'category'); = loop-category.php
    get_template_part('loop', 'single'); = loop-single.php

    Sorry for re-asking but…

    Does the word “is” in “suffix that is added” mean “it is added by developers as a standard” or that also “the one wordpress will chose when the template type matches?

    Excuse my frustration, but the words are vague for such a small description.
    There’s probably a glossary somewhere with all those terms, but I ignore it.


    Now, following the regular naming convention, in which wp uses single.php for pages and posts and NOT for the home page (at least the home page is a page?)

    My home page will contain the last post only, so I want to use the same html used for the loop in “single.php”.

    Will get_template_part('single_loop', 'index') call single_loop.php for the home page?

    So for the archives I would use get_template_part('multiple_loop', 'archive')… and it will call multiple_loop.php regardless of the template it is in, right? (e.g. that last function being in a single post page will call the multiple_loop.php file)

    In case I go crazy and want to use the multiple_loop.php file for single pages, should I use a regular include function in that case?




    Forum Moderator

    Does the word “is” in “suffix that is added” mean “it is added by developers as a standard” or that also “the one wordpress will chose when the template type matches?

    It is added by developers – ie you.



    Thanks, esmi and Zambrano. I was looking at the documentation in the codex and also confused. I’m trying to teach myself some theme development, CSS, and PHP all at the same time. Sometimes you come to a function and aren’t quite sure what it means, even with documentation on it.

    And as always, thanks for explaining what the definition of the word “is” is! =)

    Dunno if this could help at all? It’s my write-up on get_template_part

    Some people like how I write and it makes things click, some… not so much!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘get_template_part’ is closed to new replies.
Skip to toolbar