0

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

get_template_part('loop','tag');

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?

1
  • 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, 2012 at 9:29

2 Answers 2

1

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.

1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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