Title: Includes and &#039;get_template_part&#039;.
Last modified: August 31, 2016

---

# Includes and 'get_template_part'.

 *  Resolved [gulliver](https://wordpress.org/support/users/gulliver/)
 * (@gulliver)
 * [10 years ago](https://wordpress.org/support/topic/includes-3/)
 * If in a template I’m including a php file which is in the main theme directory,
   is there a reason to use ‘get_template_part’ rather than ‘include’? (Other than‘
   get_template_part’ fails silently.)
 * I can’t fully understand ‘get_template_part’, so haven’t been able to use it 
   and instead use ‘include(locate_template())’.
 * As an example, how would I use ‘get_template_part’ to include a template of ‘
   part-view-all-posts.php’?

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

 *  [David Artiss](https://wordpress.org/support/users/dartiss/)
 * (@dartiss)
 * [10 years ago](https://wordpress.org/support/topic/includes-3/#post-7413506)
 * get_template_part actually uses include itself. However, where it has an advantage
   is in making it more flexible – for example, for child themes. If you’re doing
   this theme for your own purpose only then an include should be fine, otherwise
   I’d use the template_part feature.
 *  Thread Starter [gulliver](https://wordpress.org/support/users/gulliver/)
 * (@gulliver)
 * [10 years ago](https://wordpress.org/support/topic/includes-3/#post-7413508)
 * [@dartiss](https://wordpress.org/support/users/dartiss/)… thanks.
 * I updated the initial post since your reply.
 * I think I now understand, and can use:
 *     ```
       <?php get_template_part( 'part', 'view-all-posts' ); ?>
       ```
   
 * At least I now know how to use it, although I’m still unsure if this is sensible
   way… my template files have various part-page elements for which the name begins
   with ‘part-‘.
 *  [David Artiss](https://wordpress.org/support/users/dartiss/)
 * (@dartiss)
 * [10 years ago](https://wordpress.org/support/topic/includes-3/#post-7413510)
 * Yes, sorry, looks like I’m answering a different question now 😉
 * The codex page gives a pretty good explanation of use, although I’m always a 
   big fan of just grabbing an existing theme and working things out from that
 * [https://developer.wordpress.org/reference/functions/get_template_part/](https://developer.wordpress.org/reference/functions/get_template_part/)
 * This also gives the source for get_template_part which helps explain what it 
   does above and beyond a simple includes – as I said, it uses a function to locate
   the template part, which includes looking for child themes.
 *  Thread Starter [gulliver](https://wordpress.org/support/users/gulliver/)
 * (@gulliver)
 * [10 years ago](https://wordpress.org/support/topic/includes-3/#post-7413525)
 * Thanks.
    I’m also in the habit of ‘grabbing an existing…’ – although often with
   no real understanding of what I’m doing – hence my regular appearances here asking
   for help. 🙂
 *  [David Artiss](https://wordpress.org/support/users/dartiss/)
 * (@dartiss)
 * [10 years ago](https://wordpress.org/support/topic/includes-3/#post-7413535)
 * Yes. In that case, Codex is your friend. Failing that, Google 😉
 * If you believe you’ve now sorted this, could you set the status to “resolved”?
 * Thanks.
 *  Thread Starter [gulliver](https://wordpress.org/support/users/gulliver/)
 * (@gulliver)
 * [10 years ago](https://wordpress.org/support/topic/includes-3/#post-7413548)
 * Thanks.

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

The topic ‘Includes and 'get_template_part'.’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 6 replies
 * 2 participants
 * Last reply from: [gulliver](https://wordpress.org/support/users/gulliver/)
 * Last activity: [10 years ago](https://wordpress.org/support/topic/includes-3/#post-7413548)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
