Archives

Home Forums Search Search Results for 'option_generate_blog_settings'

Search Results for 'option_generate_blog_settings'

Home Forums Search Search Results for 'option_generate_blog_settings'

Viewing 15 results - 1 through 15 (of 208 total)
  • Author
    Search Results
  • #1957481
    Chris

    Not really, but I can show you a snippet that works just fine:

    add_filter( 'option_generate_blog_settings', 'custom_author_page_settings' );
    function custom_author_page_settings( $options ) {
        $author = get_the_author_meta( 'ID' );
    
        if ( 2 === $author ) {
    	$options['author'] = false;
    	$options['single_author'] = false;
        }
      
        return $options;
    }

    So I don’t understand why the other one won’t work. Did you test the code yourself? With the new Block/Hook Elements for author meta for example?

    #1952616

    In reply to: Blog Settings

    Alan

    This is the code snippet…

    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'] = true;
    	$options['date'] = true;
    	$options['categories'] = true;
    	$options['tags'] = true;
    	$options['comments'] = false;
            $options['infinite_scroll'] = true;
    	$options['infinite_scroll_button'] = true;
    	$options['masonry_load_more'] = 'More search results';
    	$options['post_image'] = true;
    	$options['post_image_position'] = 'post-image-above-header';
    	$options['post_image_alignment'] = 'post-image-aligned-center';
    	$options['column_layout'] = false;
    	$options['featured_column'] = true;
    	$options['masonry'] = false;
        }
      
        return $options;
    }
    #1952451
    [Resolved]

    Topic: Blog Settings

    in forum Support
    Alan

    I have been eliminating a lot of redundant and unnecessary code, and it looks like my blog got messed up somehow. Please help me with the following:

    For the blog page, I want the post date, by line, and categories showing underneath the title (which is how it currently displays). The problem that I have is that the category also displays below the meta items on the blog post. I do not know how to remove this. You can see my blog settings here https://www.savacations.com/wp-content/uploads/2021/10/Blog-Page-Setup.jpg

    Additionally, the search icon widget is showing on two lines and I don’t know how to fix it.

    For the single posts, everything is mostly fine, but the categories are appearing on the meta line below the title (as I want it) and at the bottom of the post above the tags (which I don’t want). See here for an example https://www.savacations.com/where-to-stay-in-santiago-chile-centro-providencia-or-las-condes/.

    For the archives (author, category, and tag), it’s the same as the blog page above. See here for an example https://www.savacations.com/category/south-america-travel/.

    I am using the following snippets that I got from this forum over time…

    For the archive pages

    add_filter( 'generate_header_entry_meta_items', function() {
        return array(
            'date',
            'author',
    		'categories',
        );
    } );

    For the single posts

    // set entry header post meta
    add_action( 'wp', function() {
        if ( is_single() ) {
    
            add_filter( 'generate_header_entry_meta_items', function( $items ) {
                return array(
                    'date',
                    'author',
                    'categories',
                );
            } );
        }
    } );

    I tried to use the option_generate_blog_settings (which may fix all of my problems) but got an error on line 3 code see here https://www.savacations.com/wp-content/uploads/2021/10/Option-Generate-Blog-Settings.jpg

    Thanks,

    #1950713
    Frank

    Found a way to achieve the results I was hoping to get. I’m not sure how much it impacts performance though.

    Just to recap what I wanted to achieve:

    On the archive/tag archive pages for posts/custom posts types with (custom) taxonomies I used the filters ‘generate_blog_get_column_count’ and ‘option_generate_blog_settings’ to create a specific layout. Images above the Title and an excerpt etc. This can be easily done using conditionals for these filters. But once you implement an AJAX request the formatting is lost when returning the results.

    To get the image above the text part I first remove them completely from these post types:

    add_filter('generate_featured_image_output', function($image) {
    	
    	$posttype = get_post_type();
    
    	if ('custom-1' == $posttype) {
    		$image = '';
    	}
    	
    	if ( 'custom-2' == $posttype) {
    		$image = '';
    	}
    	
    	if ( 'post' == $posttype) {
    		$image = '';
    	}
       
    	return $image;
    });

    So now on either the normal pageload and the AJAX call the image is removed from the output. After that I placed it above the content in both request types and prevented them from being rendered on single posts :

    add_filter('generate_before_content', function() {
    	if ( wp_doing_ajax() && 'custom-1' == get_post_type() || 'custom-1' == get_post_type() && ! is_single() ) {
    		echo '<div class="post-image">';
    		echo the_post_thumbnail();
    		echo '</div>';
    	}
    
    	if ( wp_doing_ajax() && 'post' == get_post_type() || 'post' == get_post_type() && ! is_single() ) {
    		echo '<div class="post-image">';
    		echo the_post_thumbnail();
    		echo '</div>';
    	}	
    }, 25);

    This way the styling stays the same in both conditions.

    Hope this helps someone facing a similar problem.

    Thanks again.

    #1947673
    Frank

    Hey Tom.

    I’m trying to use taxonomies to filter using AJAX.

    Say I’m on a custom post type archive. When you first load the page I can have column width settings and post layout settings by applying ‘generate_blog_get_column_count’ and ‘option_generate_blog_settings’ using ‘is_post_type_archive(‘custom-post-type’) in the filter section.

    When using an AJAX filter I’m taking a custom taxonomy and feeding that to either a new wp_query or get_posts() function. But the query gets done outside of the loop of that archive page since it’s being requested through AJAX. So it’s not applying the column en post styling for that archive page causing the results to have a different layout when returning the data. I was trying to find the correct conditionals in your filters to still apply the correct layout when returning the filtered content.

    Maybe I’m not phrasing it correctly though. Can I for example when using a new wp_query or get_posts function tell WordPress to use a specific GeneratePress generate_blog_get_column_count and option_generate_blog_settings filter to apply to the results without being on a specific page where the filtering is recognized because of the conditinonal that was already in place?

    #1946254
    Frank

    Hi,

    I was wondering if there is a more ‘targeted’ way of triggering GeneratePress filter settings to process/output AJAX requests/data instead of using a very global term, like for example:

    function set_gp_columns( $count ) {
       if ( wp_doing_ajax() ) {
          return 25;
       }
       return $count;
    }
    add_filter( 'generate_blog_get_column_count','set_gp_columns' );

    This would affect all output using AJAX in every location it’s being used.

    As an extension of the previous question, is there a way I can use the “option_generate_blog_settings” filter to target AJAX output, or maybe a recommended way for me to include the source of the request, so I can tell the output to use the “option_generate_blog_settings” filter” as if it were being displayed when normally loading the Tag Archives for example. I figured if I could somehow include the origin request or filter the data manually using the correct filtering options you provide, I could get the output styled properly according to the page it’s being displayed on.

    Thanks in advance.

    #1935221
    Elvin
    Staff
    Customer Support

    I see.

    In that case you’ll need this filter.
    https://docs.generatepress.com/article/option_generate_blog_settings/

    As for usage, here’s an example:

    Say, you have a category named Cats with category slug “cats” and you want the author to show up on its category archive page.

    You can do it with this filter.

    add_filter( 'option_generate_blog_settings', 'lh_custom_search_results_page_settings' );
    function lh_custom_search_results_page_settings( $options ) {
        if ( is_category('cats') ) {
    	$options['author'] = true;
        }
      
        return $options;
    }

    Example #2: Displaying author on category archive of Dogs (with slug dogs) and posts of the same category.

    add_filter( 'option_generate_blog_settings', 'lh_custom_search_results_page_settings' );
    function lh_custom_search_results_page_settings( $options ) {
        if ( is_category('dogs') && in_category( 'dogs' ) ) {
    	$options['author'] = true;
    	$options['single_author'] = true;
        }
      
        return $options;
    }

    A wise man once said:
    "Have you cleared your cache?"

    #1923560
    [Resolved]

    Topic: CPT > Changing the number of columns

    in forum Support
    Brenden

    I followed the instructions provided here – https://docs.generatepress.com/article/using-columns-in-the-blog/#changing-the-number-of-columns, but I can’t get it to work. Here is my code.

    add_filter( 'option_generate_blog_settings', function( $settings ) {
        if ( is_post_type_archive( 'priorities' ) ) {
            $settings['columns'] = '33';
        }
    
        return $settings;
    } );

    While troubleshooting, I also tried this code below which did work, but I don’t want to use the Customizer setting because I need the CPT to be different from the Posts.

    add_filter( 'generate_blog_columns','tu_portfolio_columns' );
    function tu_portfolio_columns( $columns ) {
        if ( is_post_type_archive( 'priorities' ) ) {
            return true;
        }
    
        return $columns;
    }
    Elvin
    Staff
    Customer Support

    Hi there,

    I believe the variable/s for single post pages has to be the FF:

    $options['single_date'], $options['single_author'] and $options['single_categories'].

    See more here – https://docs.generatepress.com/article/option_generate_blog_settings/#options-%E2%80%98single_date%E2%80%99

    A wise man once said:
    "Have you cleared your cache?"

    #1913519
    boaz

    Hi, im trying to hide the meta author/date/categories in post belonging to certain categories,
    Any reason why this code shouldnt work (its not working for me)

    add_filter( 'option_generate_blog_settings', 'custom_page_settings' );
    function custom_page_settings( $options ) {
     if ( in_category( array(1031,1032,1020,1016,1033,1017,1015,1046,1041,1043,1034,1018,1035,1040,1044,1036,1037,1045,1022,1038,1014,1051,1,1050,1042,1054,1039,1053,1021,1048,1052,1049,1047))){
    
    		$options['author'] = false;
    		$options['date'] = false;
    		$options['categories'] = false;
    			
    	}	
      
        return $options;
    }

    thanks

    David
    Staff
    Customer Support

    Hi there,

    you can use the option_generate_blog_settings filter to enable/disable the blog options on specific templates – see here:

    https://docs.generatepress.com/article/option_generate_blog_settings/

    #1873637
    Naomi

    Hello,
    the code below works with WPML on both category archive pages but stops working when I turn on WPML string translations. Does anyone know why this could be? With a little check I could see that the code does still get past the first “if” but then the options aren’t applied. Has anyone else had this? Any suggestions welcome.

    add_filter( 'option_generate_blog_settings', 'bw_custom_archive_page_settings' );
    function bw_custom_archive_page_settings( $options ) {
    	if ( is_category( array( 8, 9 ) ) ) {
    		$options['post_image_alignment'] = 'post-image-aligned-left';
    		$options['post_image_size'] = 'medium';
    		$options['column_layout'] = false;
    		$options['featured_column'] = false;
    		$options['masonry'] = false;
    	}
    
        return $options;
    }
    #1853035

    In reply to: List individual Q&As

    David
    Staff
    Customer Support

    If you have the Full Content displayed on your blog / archives then you can use this PHP Snippet to set the excerpt for a specific category:

    add_filter( 'generate_show_excerpt', function( $show ) {
        if ( is_category( array( 'cat-term-1', 'cat-term-2', 'cat-term-3' ) ) ) {
            return true;
        }
    
        return $show;
    } );

    I included the array so you can specify multiple Category terms.

    And then you can use the option_generate_blog_settings filter to disabling other elements such as meta:

    https://docs.generatepress.com/article/option_generate_blog_settings/

    Maxime

    Hello, Leo…

    Thank you for your kind attention as well as David’s.
    David is right, there was also a snippet added in function.php. Here it is:

    add_filter( ‘option_generate_blog_settings’, ‘db_disable_columns_tribe_events’ );
    function db_disable_columns_tribe_events( $options ) {
    if ( is_post_type_archive( ‘tribe_events’ ) ) {
    $options[‘column_layout’] = false;
    }

    return $options;
    }

    I did add it now to the test site which credentials I gave to you but… to no avail.
    The List and Day views work just fine.
    The Month view is a tiny calendar. The whole filter bar is gone. You can see for yourself: http://maximeh40.sg-host.com/events/month/

    I did make the whole thing work before but… I don’t seem to be able to anymore.
    The test site that I have set up is totally clean.

    If you switch theme to “TwentyNineteen” for testing purposes, you will see that everything works perfectly… without any snippets.

    I am a bit at a loss as to what to try, mainly because the behavior is erratic (which does not make sense).

    Thank you again,

    Maxime.

    #1841887
    BreoganGal
    add_filter( 'generate_blog_get_column_count','tu_search_column_count' );
    function tu_search_column_count( $count ) {
        if ( is_search() ) {
            return 33;
        }
    
        return $count;
    }
    
    add_filter( 'option_generate_blog_settings', 'lh_search_columns' );
    function lh_search_columns( $options ) {
        if ( is_search() ) {
      $options['column_layout'] = true;
        }
      
        return $options;
    }

    This is the code of functions.php. still not working

Viewing 15 results - 1 through 15 (of 208 total)