WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

So my theme has a tag.php, that contains this line:


that runs the loop and spits out the tag entries. I'm modifying it to include post thumbnails (using if(has_post_thumbnail()) { the_post_thumbnail() }), but have run into a need to add more styling. to do this I need to get access to the code that get_template_part() is spitting out.

i know i should be able to do this somehow by creating my own loop in loop-tag.php or some such thing, but can't find an example. can someone give me a simple example of a loop-tag.php that would break the functions of get_template_part('loop','tag') into it's components?

share|improve this question
what components are you talking about? have you tried to save a copy of loop.php as loop-tag.php, which should give you the same output as you have now, but which you can then start to edit? – Michael Apr 21 '12 at 9:29
up vote 1 down vote accepted

I think you misunderstand the purpose of get_template_part(). It is a wrapper for locate_template(), which itself is just a wrapper for include().

By calling get_template_part( 'loop', 'tag' ), you are telling WordPress to look for/include a file based on the following priority:

  1. Child Theme loop-tag.php
  2. Parent Theme loop-tag.php
  3. Child Theme loop.php
  4. Parent Theme loop.php

If you need to modify the markup of the loop itself, then you simply need to modify the appropriate file, according to the above priority list - e.g. loop-tag.php in your Theme or Child Theme.

You may need to create this file; if so, copy loop.php, name the copy loop-tag.php, and edit as necessary.

share|improve this answer

The easiest way to do this is find your loop, in your case it looks like it would be in a file called loop.php.

  1. Make a backup copy of tag.php
  2. Delete get_template_part('loop','tag'); from tag.php
  3. Copy/Paste the contents of loop.php into tag.php
  4. Hit refresh

Now you can style tag.php however you want.

Note: If there is a problem make sure you did not remove the header and footer calls, or any other markup from tag.php (or loop.php), next time pastebin your whole tag.php code.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.