Return to Support

Custom Post Types and Graphene

Home Forums Graphene WordPress theme Support Custom Post Types and Graphene

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #9993

    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:

    Quote:
    /* 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?

    Thanks,

    Ken

    #45091
    Syahir Hakim
    Keymaster

    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:

    https://codex.wordpress.org/Function_Reference/get_template_part

    #45092

    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.

    Quote:
    See more on get_template_part() function here:

    https://codex.wordpress.org/Function_Reference/get_template_part

    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.