Site logo

[Resolved] Creating a custom post type and archive

Home Forums Support [Resolved] Creating a custom post type and archive

Home Forums Support Creating a custom post type and archive

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #2131083
    Filip

    Hi!

    I’m creating a Case study custom post type for my website and I’m lost.

    I tried following your tutorial but it’s still not working.

    I’ve added this code to my child theme’s functions.php:

    function create_post_type() {
    register_post_type(‘case-study’,
    array(
    ‘labels’ => array(
    ‘name’ => __(‘Case studies’, ‘textdomain’),
    ‘singular_name’ => __(‘Case study’, ‘textdomain’),
    ),
    ‘public’ => true,
    ‘has_archive’ => true,
    )
    );
    }

    add_action(‘init’, ‘create_post_type’);

    I’ve also downloaded a copy of single.php and content-single.php, renamed them to single-case-study.php and content-case-study.php and uploaded them in my child theme’s folder.

    I’ve replaced the code in a single-case-study.php (line 29) with the one you provided:

    get_template_part( ‘content’, ‘project’ );

    The thing is – I can add the case studies in the WP dashboard, but I can’t view them and see the archives (404 errors).

    Please help, thanks!

    #2131101
    Ying
    Staff
    Customer Support

    Hi there,

    You need to replace the projectwith your custom post type name in get_template_part( 'content', 'project' );

    In your case, case-study.

    #2131131
    Filip

    Oh, I’ve replaced that too, just as you said (accidentally pasted the default line in the original post).

    #2131167
    Ying
    Staff
    Customer Support

    Can you try change permalinks setting to post name to test?

    The setting can be found at dashboard > settings > permalinks

    #2131558
    Filip

    It works now.

    Thanks so much!

    #2131613
    Filip

    Everything’s perfect but there’s still one more issue.

    I’ve applied the same template for a blog post and a case study – but the width of the content for the case study CPT is not applied.

    Here’s the image.

    1st img – post
    2nd img – case study
    3rd img – content settings applied to both

    #2131640
    David
    Staff
    Customer Support

    Hi there,

    change:

    get_template_part( 'content', 'case-study' );

    to:

    generate_do_template_part( 'case-study' );

    #2131663
    Filip

    Works fine now, thanks once more!

    #2131675
    David
    Staff
    Customer Support

    Glad to hear that!

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