[Resolved] Different number of Blog display columns for different blog categories

Home Forums Support [Resolved] Different number of Blog display columns for different blog categories

Home Forums Support Different number of Blog display columns for different blog categories

  • This topic has 13 replies, 3 voices, and was last updated 2 years ago by Ying.
Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #2171657
    robert

    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!

    #2171735
    Leo
    Staff
    Customer Support

    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 🙂

    #2172763
    robert

    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

    #2172769
    Ying
    Staff
    Customer Support

    Hi Robert,

    This should be the filter you are looking for:
    https://docs.generatepress.com/article/option_generate_blog_settings/

    #2172772
    robert

    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;
    }

    #2172790
    Ying
    Staff
    Customer Support

    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' ) ).

    #2172794
    robert

    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;
    }

    #2172805
    Ying
    Staff
    Customer Support

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

    #2172818
    robert

    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;
    }

    #2172880
    robert

    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;
    }

    #2172922
    Ying
    Staff
    Customer Support

    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;
    }
    #2172923
    Ying
    Staff
    Customer Support

    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') ) ){

    #2172930
    robert

    thanks so much!

    #2172933
    Ying
    Staff
    Customer Support

    You are welcome 🙂

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