[Resolved] Different blog columns layout on specific category?

Home Forums Support [Resolved] Different blog columns layout on specific category?

Home Forums Support Different blog columns layout on specific category?

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #202791
    Alvaro

    Hi,

    I need a blog columns layout, using the Blog add-on, different on one category archive page. Is there a hook for that?

    I know I can change the sidebar layout by category using GP hooks and conditionals (https://generatepress.com/knowledgebase/choosing-sidebar-layouts/) but I don’t know how to have different columns # in a blog column layout for a specific category.

    I need one category to have 3 columns and no sidebar, I need other to have 2 columns and the right sidebar.

    Thanks.

    #202898
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    There’s a filter to enable/disable columns all together just like the sidebar layout, but there’s currently no filter to choose how many columns using a filter.

    I’ve added this to the list of improvements for the next update – I’ll update this thread once I have it implemented.

    #202915
    Alvaro

    So, the only imediate way is to have a category specific archive template, right?

    Thanks Tom.

    #202965
    Tom
    Lead Developer
    Lead Developer

    I just added the filter, so in GP Premium 1.2.87 you’ll be able to do this:

    add_filter( 'generate_blog_get_column_count','generate_custom_column_count' );
    function generate_custom_column_count()
    {
        if ( is_category( 'Whatever' ) )
            return 3;
    
        if ( is_category( 'Example' ) )
            return 2;
    
        // Or else, return the default
        return $count;
    }

    If you’d like to try it before I release it just shoot me an email 🙂

    #273746
    Alvaro

    Hi Tom,

    I’m sure this was working before but now I’m not getting the number of columns. It seems that, when I use this filter, the generated class is grid-X, with X being the number of columns instead of the matching grid class, it should be grid-33 for 3 columns, grid-25 for 4 columns, etc., right?

    I solved it by changing the filter code to the actual class count, like this:

    /**
     * Set the page columns per category
     *
     */
    add_filter( 'generate_blog_get_column_count','generate_custom_column_count' );
    function generate_custom_column_count()
    {
        if ( is_category( 'noticias' ) )
            return 25;
    
        if ( is_category( 'atas' ) )
            return 100;
    
        // Or else, return the default
        return $count;
    }

    but I’m pretty sure this was not intended. Was it?

    Thanks.

    Álvaro

    #273905
    Tom
    Lead Developer
    Lead Developer

    Yea, that’s the intended use, although I agree it’s not very intuitive. I just updated the documentation here: https://docs.generatepress.com/article/using-columns-in-the-blog/#changing-the-number-of-columns

    Thanks for pointing that out 🙂

    #274922
    Alvaro

    OK. Thanks Tom.

    #275115
    Tom
    Lead Developer
    Lead Developer

    No problem 🙂

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