Archived topic
Different blog columns layout on specific category?
7 replies · Started by Alvaro on June 17, 2016
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.
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.
So, the only imediate way is to have a category specific archive template, right?
Thanks Tom.
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 :)
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
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 :)
OK. Thanks Tom.
No problem :)