Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

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
add comment

2 Answers

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
add comment

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
add comment

Your Answer

 
discard

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.