I have a custom post type of 'competitions'. In order to customise the display for this CPT in, for example, category listings I am doing the following:

  • Create a category-competitions.php file
  • Create a content-competitions.php file
  • Within the loop in that file, call get_template_part('content-competitions', get_post_format() )'

This works, but I'm not sure this is the correct method. Is it necessary to include the whole category-competitions.php file to change that one line, or is there a built in way to achieve this that I am missing?

1 Answer 1


What you've done will include content-competitions-<post-format>.php. I don't know if that is what you want, but that is correct as far as structure goes.

I also don't know what you mean by "to change that one line", but get_template_part will use the two parameters to construct a file name/path so, yes, you do need to include all of it. Take a look at the explanation in the Codex:

<?php get_template_part( 'loop', 'index' ); ?>

will do a PHP require() for the first file that exists among these, in this priority:


What you get with get_template_part is

  1. "child or parent theme name", first one then the other
  2. plus "first parameter"
  3. Plus "-"
  4. plus "second parameter"
  5. plus ".php"

Or ...

  1. "child or parent theme name", first one then the other
  2. plus "first parameter"
  3. plus ".php"

... if nothing is found having the second parameter.

There is no shortcut. WordPress can't guess what file you want to include.

If you could name your files something like postformat.php you could get away with using only the first parameter though:

get_template_part( get_post_format() );

I don't know if that is a possibility as that post-format.php file would be used for any post having that named post format.

  • Thanks for your reply. As I said, it does work the way I have set it up. The "one line" refers to duplicating the entire category file in order to add "-competitions" into the get_template_part() function. You say wordpress can't guess what file I want, but the file I want could be identified purely by its name - if there was a better way of handling it. That was my question - "is there a better (more correct) way?"
    – EpF
    Commented Jun 23, 2013 at 17:40
  • 'That was my question - "is there a better (more correct) way?' -- And that is the question I answered. "No". There is no shortcut. If you don't provided the complete name WordPress cannot locate the file, though the second parameter is optional. You could save part of the filename to a variable but that is the only (maybe) simplification that I can think of.
    – s_ha_dum
    Commented Jun 23, 2013 at 17:50
  • Now I understand what get_template_part really does!
    – lowtechsun
    Commented Jun 15, 2017 at 16:07

Your Answer

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

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