[Resolved] Custom post type archive layout questions

Home Forums Support [Resolved] Custom post type archive layout questions

Home Forums Support Custom post type archive layout questions

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #2380823
    David

    Hello

    I’ve set up a custom post type called products.

    I’ve then set up a block element using the Element Type : Content template

    This works fine and products are showing up…
    https://www.alfies-antiques.com/products/

    I added this code so the custom post type shows in 3 columns

    //ADD COLUMNS TO CUSTOM POST TYPES
    add_filter( 'generate_blog_columns', function( $columns ) {
        if ( 'products' === get_post_type() && ! is_singular() ) {
            return true;
        }
    
        return $columns;
    } );

    My first questions is, how do I get it to show 2 columns on mobile?

    My second questions is, why do the products not show up on standard taxonomy category pages…
    https://www.alfies-antiques.com/category/handles-hooks/

    Thanks
    Dave

    #2381365
    David
    Staff
    Customer Support

    Hi there,

    1. you can use this CSS to force the CPT columns to 2 on mobile:

    
    @media (max-width: 768px) {
        .archive .generate-columns {
            width: 50% !important;
        }
        .archive .generate-columns {
            padding-left: 20px !important;
        }
    }

    2. Category archives will only display the post post-type by default.
    Use the pre_get_posts hook to add others:

    
    function db_multi_post_type_categories($query)
    {
        if($query->is_main_query() && is_category()){
            $query->set('post_type', ['post', 'your-post-type']);
            return;
        }
    }
    add_action('pre_get_posts', 'db_multi_post_type_categories');
    #2381382
    David

    Thanks David – how do I show 2 columns on the post category archive page?

    #2381445
    David
    Staff
    Customer Support

    I edited the CSS above to apply to all archives.

    #2383274
    David

    Thanks David

    #2383883
    David
    Staff
    Customer Support

    You’re welcome

    #2395200
    David

    Hi David

    So I’ve updated my custom post type archive layout, by setting up a new Element Block and using the new Element Type > Loop template, which is great by the way.

    Is it possible for it to use the loop template for taxonomy category pages though? So for example this category only has one product assigned to it, but it’s showing all custom post type products…

    Is it possible to set up a new loop template, that shows products per category? I don’t want to be setting it up loops for each individual category though.

    https://www.alfies-antiques.com/category/desks/

    Thanks
    Dave

    #2395612
    David
    Staff
    Customer Support

    So for the Loop Element – its designed to use the Inherit Query from Template option in the Query Loop Block.
    Then if you set your Display Rules to eg. Category Archive, it will pull in just the posts that match that terms of the archive page the user is viewing.

    #2395699
    David

    Thanks David, that’s great – loving the new loop template

    #2396318
    David
    Staff
    Customer Support

    Awesome – glad to hear that!

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