Archived topic
Making custom post type looking as normal single post (first)
15 replies · Started by Georg on May 25, 2016
Hi Tom,
i'm going crazy to create a custom post type looking like normal single post.
I've created a custom post type, copied your single post template (single.php) and content-single.php. After naming the copy as my post type e.g. single-test.php it is used as wanted.
But: After the the title there's no author and date shown and at the end there are no Tags and Categories.
Do you have an idea?
Thanks in advance!
Currently there's a check inside the actual functions that show those elements looking for the "post" post type.
In the next version (GP 1.3.30), I've removed that and added those elements into hookable functions so we can add them to different post types.
If you want to post in this topic once 1.3.30 is released (this week), I can give you the code for it :)
Hi Tom,
thanks for the answer.
If the solution is released this week, i can wait. Otherwise i would appreciate, if you give me the code!
Thank you! :)
Best
Georg
If I don't get it released tomorrow or Friday I'll circle back and give you a solution :)
Cool! Thank you! :)
Hi Tom,
i've installed the newest version of GeneratePress now.
Testing it with custom post types, but it seems nothing changed. :(
What is my fault?
I use the Plugin "Custom Post Type UI" from Webdev Studios to create custom post types, then copy over your single post template unchanged with e.g. single-test.php in my child theme folder, but even the title meta (date and author) or other post meta like tags and categories wont be shown.
Do you have an idea?
Thanks in advance!
Best
Georg
Hi,
with this code in my child them folder's function.php now i've got the solution for me:
//Gets post cat slug and looks for single-[cat slug].php and applies it
add_filter('single_template', create_function(
'$the_template',
'foreach( (array) get_the_category() as $cat ) {
if ( file_exists(STYLESHEETPATH . "/single-{$cat->slug}.php") )
return STYLESHEETPATH . "/single-{$cat->slug}.php"; }
return $the_template;' )
);
Thanks
Georg
With the new version we'll need to add some custom code still so it works for your specific custom post type.
Let me know if you'd like that solution or if you're happy with the one you found :)
Hi Tom,
my last posted solution is even not as good as i thought.
Perhaps you give me yours so i can give it a try! :)
Thanks in advance!
Best
Georg
You can do something like this:
if ( ! function_exists( 'generate_post_meta' ) ) :
/**
* Build the post meta
*
* @since 1.3.29
*/
add_action( 'generate_after_entry_title', 'generate_post_meta' );
function generate_post_meta()
{
if ( 'post' == get_post_type() || 'your-post-type' == get_post_type() ) : ?>
<div class="entry-meta">
<?php generate_posted_on(); ?>
</div><!-- .entry-meta -->
<?php endif;
}
endif;
if ( ! function_exists( 'generate_footer_meta' ) ) :
/**
* Build the footer post meta
*
* @since 1.3.30
*/
add_action( 'generate_after_entry_content', 'generate_footer_meta' );
function generate_footer_meta()
{
if ( 'post' == get_post_type() || 'your-post-type' == get_post_type() ) : ?>
<footer class="entry-meta">
<?php generate_entry_meta(); ?>
<?php if ( is_single() ) generate_content_nav( 'nav-below' ); ?>
</footer><!-- .entry-meta -->
<?php endif;
}
endif;
Just change the "your-post-type" to the name of your post type :)
Thank you, Tom!
I'll try it out and give you a response soon.
Best
Georg
Ok Tom,
with the custom post type it is functionable now. Great! :-)
Only problem is now that i can't edit the title of the category archive for this new post type. There is only "Archive" displayed, no matter what i type in.
I want to edit this in "edit category".
Do you have an idea?
Thanks in advance!
Best
Georg
Hi Tom,
do you have an idea, what i can do with the category archive title?
I can't change it. There is only "archive" displayed. :(
Best regards
Georg
Hi Georg,
You would have to overwrite this function to include logic specific to your custom post type: https://gist.github.com/generatepress/fe5309693719d138dbcf84381eb9a6b3
Hi Tom,
tried out and giving up now. Because it's too time intensive.
Maybe later i'll try it again.
Sorry, and thank you for helping!
Best
Georg
