Custom Post Types and Graphene
-
Mod
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.phpand name itsingle-{posttype}.php. Of course, in Graphenesingle.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.phptosingle-stories.php, it works, but I can’t really make any changes, sincesingle.phpjust wraps Graphene’s loop with the header and footer.So I copied
loop-single.phptosingle-stories.phpand 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 ofloop-single.phpand<?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
Admin
Hi Ken,
The right way is to copy Graphene’s
single.phpfile and rename itsingle-stories.php(as you did the first time). Then, you can go either two ways:- Copy the content of Graphene’s
loop-single.phpfile intosingle-stories.php, replacing the line that containsget_template_part( 'loop', 'single' ), or - Change
get_template_part( 'loop', 'single' )insingle-stories.phptoget_template_part( 'loop', 'stories' ), and then copy Graphene’sloop-single.phpfile and rename itloop-stories.php.
See more on
get_template_part()function here:https://codex.wordpress.org/Function_Reference/get_template_part
Mod
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!
- Copy the content of Graphene’s
Viewing 3 posts - 1 through 3 (of 3 total)
- You must be logged in to reply to this topic.
