Site logo

Archived topic

Different number of Blog display columns for different blog categories

13 replies · Started by robert on March 29, 2022

Viewing posts 1–14 of 14

Hello, I have several categories of blogs that i wish to show in a single column, whilst the rest of the site is categories is two columns.
I have read the below link but unfortunately need more simple instructions on how to impliment.

Lets say for example that the name of the categroy is "Best Lounge in Colorado"

https://docs.generatepress.com/article/using-columns-in-the-blog/#changing-the-number-of-columns,

Wpuld it be possible to get a step by step guide on how to do this?.

Thanks!

Hi there,

The code should be something like this:

add_filter( 'generate_blog_get_column_count','tu_search_column_count' );
function tu_search_column_count( $count ) {
    if ( is_category() ) {
        return 100;
    }

    return $count;
}

Then just replace is_category() with the right conditional tag as shown here:
https://codex.wordpress.org/Conditional_Tags#A_Category_Page

The is_category( array( 9, 'blue-cheese', 'Stinky Cheeses' ) ) should be what you need with multiple categories.

Adding PHP: https://docs.generatepress.com/article/adding-php/

Let me know if this helps :)

This worked thanks so much. How would I add a filter so that the defined category page also showed all the contents of each article instead of just the first 25 charactors?... And is it possible to remove the read more button from these specific categories?.

The only other issue is that when i create a custom block using generateblocks and apply it to a category, the new category is still not one column. With this method I have deactivated the read more button and show all post content instead of the excerpt.

thanks

thanks!! So it would be something like this?.

How would I apply this to specific categories?....

add_filter( 'option_generate_blog_settings', 'lh_custom_search_results_page_settings' );
function lh_custom_search_results_page_settings( $options ) {
if ( is_search() ) {
$options['read_more_button'] = false;
$options['date'] = false;
$options['categories'] = false;
$options['tags'] = false;
$options['comments'] = false;

}

return $options;
}

You just need to replace is_search() with is_category('your-category-slug').

For multiple categories, the conditional tag would be something like:
is_category( array( 9, 'blue-cheese', 'Stinky Cheeses' ) ).

the below seems to not have any effect......

add_filter( ‘option_generate_blog_settings’, ‘lh_custom_search_results_page_settings’ );
function lh_custom_search_results_page_settings( $options ) {
if ( is_category('best-lounge', 'best-chair') ) {
$options[‘read_more_button’] = false;
$options[‘date’] = false;
$options[‘categories’] = false;
$options[‘tags’] = false;
$options[‘comments’] = false;

}

return $options;
}

Try use this format:
is_category( array( 'best-lounge', 'best-chair' ) )

thanks so much....when I add the array I get a syntax error....

add_filter( ‘option_generate_blog_settings’, ‘lh_custom_search_results_page_settings’ );
function lh_custom_search_results_page_settings( $options ) {
if ( is_category( array(‘best-lounge’, ‘best-chair’) ) {
$options[‘read_more_button’] = false;
$options[‘date’] = false;
$options[‘categories’] = false;
$options[‘tags’] = false;
$options[‘comments’] = false;

}

return $options;
}

ahh, this bit of code worked....

So I cannot choose to view the entire article with these options?. I just have the 25 charactor excerpt to fix....

add_filter( 'option_generate_blog_settings', 'lh_custom_search_results_page_settings' );
function lh_custom_search_results_page_settings( $options ) {
if ( is_category('best-lounge', 'best-chair') ) {
$options['read_more_button'] = false;
$options['date'] = false;
$options['categories'] = false;
}

return $options;
}

Try this filter to show full content:

add_filter( 'generate_show_excerpt', 'show_full_content');
function show_full_content($show_excerpt) {
 if(is_category(array('category1','category2')))	 {
	 return false;
 }
	return $show_excerpt;
}

when I add the array I get a syntax error….

You are missing one ) here: if ( is_category( array('best-lounge', 'best-chair') ) {

It should've been: if ( is_category( array('best-lounge', 'best-chair') ) ){

thanks so much!

You are welcome :)

This archived topic is closed to new replies.