0

I am creating a small blog about my trekking and camping experience. Since different experiences - like campsites, treks and tour operators - have different metadata, I have created a custom post types (e.g. campsite), associated with custom field types (e.g. price, water_supply).

Now I'm trying to use these fields in my child theme. I've copied twenty-twelve - the parent - single.php to single-campsite.php, and started digging in.

The problem is that the entire post content - title, content, and date - is created from this single line:

<?php get_template_part( 'content', get_post_format() ); ?>

How do I edit the post internals, e.g. insert custom fields between the title and the contents, or remove the date below?

1 Answer 1

1

That statement grabs a file called content-post-format.php in the theme directory, depending on the post format. Posts will grab content.php since there is no post format.

Copy the information out of content.php into single-campsite.php and go from there. Alternatively, you can create a copy of content.php called content-campsite.php and call:

<?php get_template_part( 'content', 'campsite' ); ?>
4
  • +1 Great. The concept of get_template_part is a bit confusing.
    – Adam Matan
    Apr 1, 2013 at 14:47
  • Yeah, it's a little at first but it's nice to keep your theme organized by section. I use this for comments, post data, all kinds of things. Apr 2, 2013 at 15:16
  • What's the general idea behind this function?
    – Adam Matan
    Apr 2, 2013 at 15:27
  • 1
    A simple API to include theme files correctly. It basically concatenates the first string and the last string with a dash in the middle and looks for that file name with a PHP extension. If it doesn't find that, it falls back on just the first string for a file name. Basically, it tries for a specific file but has a fall back if not. Apr 3, 2013 at 16:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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