Custom Post Types and Graphene

  • Mod

    Kenneth John Odle


    I starting working on some custom post types, and while I think I’ve got it mostly figured out, I’m a little confused about how Graphene handles them in regard to custom template files. I was able to create a CPT called “stories”.

    According to the Codex, the way to create a custom template file is to make a copy of single.php and name it single-{posttype}.php. Of course, in Graphene single.php, it says:

    /* Run the loop to output the posts.

    * If you want to overload this in a child theme then include a file

    * called loop-single.php and that will be used instead.


    If I copy single.php to single-stories.php, it works, but I can’t really make any changes, since single.php just wraps Graphene’s loop with the header and footer.

    So I copied loop-single.php to single-stories.php and that worked, but it only ran the loop, of course. No header, no footer, no sidebars.

    I then added <?php get_header(); ?> to the top of loop-single.php and <?php get_footer(); ?> to the bottom. It works. I was able to make the changes I needed.

    Did I do this the right way? Am I likely to break anything down the road using this approach? (It works in localhost; I haven’t put it on the web yet.) Is there a better, more efficient way to do this?




    Syahir Hakim


    Hi Ken,

    The right way is to copy Graphene’s single.php file and rename it single-stories.php (as you did the first time). Then, you can go either two ways:

    1. Copy the content of Graphene’s loop-single.php file into single-stories.php, replacing the line that contains get_template_part( 'loop', 'single' ), or
    2. Change get_template_part( 'loop', 'single' ) in single-stories.php to get_template_part( 'loop', 'stories' ), and then copy Graphene’s loop-single.php file and rename it loop-stories.php.

    See more on get_template_part() function here:


    Kenneth John Odle


    Thank you. What I did worked, but it didn’t feel right. I think I like method #2 better, as it aligned better with Graphene’s file structure.

    See more on get_template_part() function here:

    Can’t believe I missed that in the Codex! I think I’ve read every page except that one.

    Thanks again!

Viewing 3 posts - 1 through 3 (of 3 total)

  • You must be logged in to reply to this topic.