[Resolved] Advice on creating a custom post type

Home Forums Support Advice on creating a custom post type

  • This topic has 13 replies, 4 voices, and was last updated 4 months ago by Elvin.
Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #1450216
    Andrew

    First a little back story. I’m not a developer but can build things within blocks. What I want to do is create a second “blog” within my site (not actually a blog but a post type with the same functionality but separate from the main blog with a different layout).

    After much research it looks like the solution is to create a custom post type.

    I installed the custom post type UI plugin. All good, created the post type and custom categories, no problem. Then hit a roadblock – how to create a page to display the new custom posts, similar to how the Blog page works.

    Apparently there’s not an easy way to do this, hence I’m going to have to hire a developer to do this for me.

    Now, I have mixed results with the freelancer market and find it helps to be very specific with my request.

    Therefore, what is the recommended way to create CPTs and the corresponding page to display the list of CPTs?

    I’m asking here as it needs to be in a way that interacts cleanly with the GP templates. I am moving my site to GP as it is super fast and I don’t want to remove those performance benefits with unnecessary plugin bloat.

    I want to be clear with the freelancer on what I expect them to do and what approach they should take; potentially even referring them to this post.

    #1450390
    David
    Staff
    Customer Support

    Hi there,

    how does the CPT differ from the standard single post ?
    Does it requite extra meta/custom fields or its own custom taxonomy ?

    #1450574
    Andrew

    The CPT can have the same appearance as the standard single post.

    By taxonomy I assume you mean categories/tags? In which case, this will be specific to the CPT area.

    A primary difference will be the “blog-equivalent” page, the page which will display the snippets of the CPT posts, which will have a different layout and sidebars than the blog page.

    #1451168
    Tom
    Lead Developer
    Lead Developer

    I mainly mean is it possible to view the archives for your custom taxonomy on the frontend? My understanding is that the CPT must have archives enabled in order to view archives for posts in that CPT (regardless of taxonomy).

    #1451249
    Andrew

    My ignorance of WP nomenclature will now reveal it’s ugly head. In laymans terms what do you mean by archives? Are these older posts? Let me explain what I want and why.

    I have a standard blog, all good, all working as expected.

    I also have a bunch of client case studies, that grows over time. Instead of creating specific pages for each case study, then having to edit the case study page for these to appear, I prefer to do this in a blog style. This would also mean case studies become easy to split by industry using categories or tags.

    Ideally I create a case study, give it the relevant industry category or tag (not bothered which, result is the same), and it will automatically appear in the case study list. The user will be able to segment the case studies using the industry category/tag.

    I can’t use the current blog and do this with smarter use of categories as I don’t want the case study page to have the same sidebars as the blog. Hence looking at CPTs as an option to do this.

    Does that help?

    #1451385
    Elvin
    Customer Support

    Hi Andrew,

    My ignorance of WP nomenclature will now reveal it’s ugly head. In laymans terms what do you mean by archives? Are these older posts? Let me explain what I want and why.

    “Archive pages are generated to organize a list of posts under a specific post type, category, or tag. For example, a blog is a great illustration of the WordPress archive page. Archives are also available for the custom post type.” – VisualComposer

    …I prefer to do this in a blog style.

    Archive pages are basically a “blog style” lists. I believe it fits nicely to what you want to do.

    I can’t use the current blog and do this with smarter use of categories as I don’t want the case study page to have the same sidebars as the blog. Hence looking at CPTs as an option to do this.

    I believe you can use WordPress Archive Pages for this. Is “having the same sidebar” the only issue? You can simply remove that with GP Premium’s Layout element for specific post-type/categories/tags archive pages.

    And if you don’t want the case study post type to appear on the blog list, you can exclude them from the main blog query. – https://docs.generatepress.com/article/exclude-categories-from-posts-page/

    A wise man once said:
    "Have you cleared your cache?"

    #1451768
    Andrew

    Thanks for the input and archive explanation. I’m not 100% sure what you’re suggesting. If I use the standard posts then certain case study categories are simple to remove.

    Then how do I get only the case study category posts to appear in a new archive page, with a different layout to the Blog page? I brought CPTs into the mix as I thought that may be easier with a custom post, however if it’s the same to do using the usual posts, then no problem to use what’s existing.

    #1451861
    David
    Staff
    Customer Support

    OK so the simplest solution is to use the default Post type.
    With specific categories for your Case Studies. All of these special posts should have a Parent Category of eg. Case Study.

    First ( if required ) you can exclude Case Studies category for the main query ( blog ) – this article explains how:

    https://docs.generatepress.com/article/exclude-categories-from-posts-page/

    Now a couple of options for creating a separate Layout for the case studies:

    1. The Layout Element – which you can use to remove elements such as sidebars:
    https://docs.generatepress.com/article/layout-element-overview/

    For its display rules you would use:
    For Archives: Post Category Archives > Case Studies.
    For singles: Post Category > Case Studies.

    2. The option_generate_blog_settings filter

    https://docs.generatepress.com/article/option_generate_blog_settings/

    With this we can write a custom filter to change the Customizer > Layout > Blog settings for a specific template. Happy to help with that if required.

    Let us know.

    #1452157
    Andrew

    Thanks for providing all of that information, this theme is very powerful, really good. I think we’re getting somewhere now, which is great, but not sure if there’s any way to avoid a CPT. Here are the things I would like to change, but may not be possible using the standard post / layout element option:

    1. The case study post URL; ideally I would like this to be /case-studies/case-study-post. It’s actually coming out with the blog URL: /blog/case-study-post.

    2. The Case Study category page, built using elements, is it possible to alter the URL? It’s coming out as /blog/category/case-study-category-name/. Ideally I would like this to be /case-studies/.

    3. The Case Study category page is displaying the case study posts with the same layout as the blog page; is there anyway to customise this? The blog is currently 2 columns-medium image, the case study ideally would be 1 column – small image. (I can compromise, just like to understand what’s possible)

    4. The Case Study category page; is it possible to customise the side bar specifically for this page, so it displays differently to the blog page? The blog page displays recent posts and all categories. I prefer the case study page only displays relevant case study sub-categories (or relevant tags used with the case study posts should sub-categories not work). On that page I want the user to be able to select Industry 1, Industry 2, etc, either by sub-categories, tags, or some other medium (I am even considering a second menu but need to better explore how this works)

    And I have to give a huge thanks for the assistance you’re giving here, it’s very useful, I’m starting to understand how great GP actually is. I thought the theme was good but the service is making it a class above.

    #1452241
    David
    Staff
    Customer Support

    1 and 2 can generally be handled by an SEO plugin. If you’re not using one and want to minimise writing redirects in PHP then maybe this plugin will do:

    https://wordpress.org/plugins/custom-permalinks/

    3. Blog options filter:
    https://docs.generatepress.com/article/option_generate_blog_settings/
    You can include any options you need:

    For example to remove Columns on Case Studies category would be this:

    add_filter( 'option_generate_blog_settings', 'lh_custom_search_results_page_settings' );
    function lh_custom_search_results_page_settings( $options ) {
        if ( is_category( 'Case Studies' )  ) {
    	$options['column_layout'] = false;
        }
      
        return $options;
    }

    More info on Conditional Tags: https://codex.wordpress.org/Conditional_Tags

    To change the Image size we use this filter: generate_blog_image_attributes

    Example:

    add_filter( 'generate_blog_image_attributes','tu_variable_image_sizes' );
    function tu_variable_image_sizes( $atts ) {
        if ( is_category( 'Case Studies' ) {
            $atts[ 'width' ] = 250;
            $atts[ 'height' ] = 170;
            $atts[ 'crop' ] = true;
        }
        return $atts;
    }

    4. Specific sidebars will need a plugin like Content Aware Sidebars. Then you can add whatever widgets you need for this specific category.

    NOTE All the code here is PHP:
    https://docs.generatepress.com/article/adding-php/

    #1452812
    Andrew

    Thanks, the custom permalinks plugin is great. I am also using the SEO Framework, but it doesn’t have the full permalink changing capability.

    The Custom Sidebars are also great. It basically leaves one item. The sidebar shows all categories. I only want it to show subcategories of the Case Studies – which would be the industries. Do you know if this is possible?

    All other categories, which are displayed in the blog page sidebar, aren’t needed, only the case study sub categories. I guess in WP speak it’s a customised widget? But does this need a custom category taxonomy or is there a workaround?

    #1453059
    Elvin
    Customer Support

    The Custom Sidebars are also great. It basically leaves one item. The sidebar shows all categories. I only want it to show subcategories of the Case Studies – which would be the industries. Do you know if this is possible?

    You can use Widget Logic(free) plugin or Widget Context Pro(paid) for this.

    Widget Logic allows you to add conditional/logic codes on your Appearance > Widgets so you can control where they display. Widget Context Pro does the same thing except you don’t have to code as they provide the dropdown menu for display location rules.

    All other categories, which are displayed in the blog page sidebar, aren’t needed, only the case study sub categories. I guess in WP speak it’s a customised widget? But does this need a custom category taxonomy or is there a workaround?

    Yes you can use a customized widget. Or you can get a plugin for it like this one. https://wordpress.org/plugins/sub-categories-widget/

    And no it doesn’t need any custom category taxonomy.

    A wise man once said:
    "Have you cleared your cache?"

    #1454103
    Andrew

    Thanks for all of the help with this, the solution is working well. For your interest, I display the Case Study category in the menu and use the following plugins:

    Code Snippets – to remove the Case Study posts from the Blog section

    Content Aware Sidebars – to allow a specific sidebar for the Case Study category & sub-category pages

    Sub Categories Widget – so I can only show specified sub-categories within the Case Study category sidebar

    Custom Permalinks – to set the URLs to something user-friendly for the Case Study category and sub-categories, and for the actual Case Study post URLs. In other words removing the word “blog” and “category” from these URLs.

    #1454421
    Elvin
    Customer Support

    Oh wow, nice one! Thanks for sharing this.

    No problem. Let us know if you have any further questions. 🙂

    A wise man once said:
    "Have you cleared your cache?"

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