WordPress.org

Ready to get started?Download WordPress

Forums

get_template_part (7 posts)

  1. Zambrano Sergio
    Member
    Posted 3 years ago #

    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:

    $name
    (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
    ?
    Thanks.

  2. esmi
    Forum Moderator
    Posted 3 years ago #

    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

  3. Zambrano Sergio
    Member
    Posted 3 years ago #

    Sorry for re-asking but…

    esmi:
    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.

    Thanks.

  4. Zambrano Sergio
    Member
    Posted 3 years ago #

    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?

    Thanks.

  5. esmi
    Forum Moderator
    Posted 3 years ago #

    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.

  6. StandardExcellence
    Member
    Posted 2 years ago #

    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! =)

  7. Rev. Voodoo
    Volunteer Moderator
    Posted 2 years ago #

    http://vudu.me/cy
    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!

Topic Closed

This topic has been closed to new replies.

About this Topic