[Resolved] Making custom post type looking as normal single post (first)

Home Forums Support [Resolved] Making custom post type looking as normal single post (first)

Home Forums Support Making custom post type looking as normal single post (first)

Viewing 15 posts - 1 through 15 (of 16 total)
  • Author
    Posts
  • #196633
    Georg

    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!

    #196704
    Tom
    Lead Developer
    Lead Developer

    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 πŸ™‚

    #196804
    Georg

    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

    #196858
    Tom
    Lead Developer
    Lead Developer

    If I don’t get it released tomorrow or Friday I’ll circle back and give you a solution πŸ™‚

    #197204
    Georg

    Cool! Thank you! πŸ™‚

    #197576
    Georg

    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

    #197642
    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

    • This reply was modified 5 years, 1 month ago by Georg.
    #197673
    Tom
    Lead Developer
    Lead Developer

    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 πŸ™‚

    #197677
    Georg

    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

    #197725
    Tom
    Lead Developer
    Lead Developer

    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 πŸ™‚

    #197902
    Georg

    Thank you, Tom!

    I’ll try it out and give you a response soon.

    Best

    Georg

    #197964
    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

    #198889
    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

    #198916
    Tom
    Lead Developer
    Lead Developer

    Hi Georg,

    You would have to overwrite this function to include logic specific to your custom post type: https://gist.github.com/generatepress/fe5309693719d138dbcf84381eb9a6b3

    #199107
    Georg

    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

Viewing 15 posts - 1 through 15 (of 16 total)
  • You must be logged in to reply to this topic.