[Resolved] columns blog-home/archive/woocommerce-shop

Home Forums Support [Resolved] columns blog-home/archive/woocommerce-shop

Home Forums Support columns blog-home/archive/woocommerce-shop

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #745499
    horst

    hello everybody,

    thanks again for this beautiful theme and its great support. (i recently prolonged my license until 2020)!
    i have perhaps an easy to solve problem, but dont know which would be the best way to do it.

    on my homepage (i.e. the blogpage) i want to display one column of latest posts (and two sidebars), on the archive pages two columns (and one sidebar.)

    i configured GP to display one column of posts and added the following code-snippet:

    add_filter( 'generate_blog_columns','tu_portfolio_columns' );
    function tu_portfolio_columns( $columns ) {
        if ( is_archive() ) {
             return 50;
        }
    
        return $count;
    }

    it worked fine, until i added a woocommerce shop. now on the shop-page the woocommerce columns would only display 50% wide. it seems, that is_archive also affects the shop_page.

    is there a way have different settings for displaying columns between archives (2 columns) / blog-homepage (1 column) and the woocommerce shop-page (1 column and three products in a row, which can be configured easily and seperately through customizer)?

    and my second question: because i am using two columns for archives: i would need to display the double amount of posts for the archive pages (or only half the posts on home page.) how can i achieve this?

    any help is appreciated.
    thanks, horst

    #745720
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    Thanks for renewing!

    Try this as your function:

    add_filter( 'generate_blog_columns', function( $columns ) {
        if ( function_exists( 'is_shop' ) && is_shop() ) {
             return $columns;
        }
    
        if ( is_archive() ) {
             return 50;
        }
    
        return $columns;
    } );

    For your second question, try this:

    add_action( 'pre_get_posts', function( $query ) {
        if ( ! $query->is_main_query() || is_admin() ) {
            return;
        }
    
        if ( $query->is_archive ) {
            $query->set( 'posts_per_page', 20 );
        }
    }, 1 );

    You can adjust the posts_per_page to whatever.

    Let me know if that helps or not πŸ™‚

    #745814
    horst

    thanks tom for your fast reply!

    problem number one is solved! thanks!

    for the second problem -> the number of posts:

    with your code snippet i am getting a white screen…

    i also tried another code from the support forum before:

    add_filter('pre_get_posts', 'posts_on_page', 1);
    
    function posts_on_page($query){
        if ( $query->is_home() && $query->is_main_query() && ! is_admin() ) {
          $query->set( 'posts_per_page', 12 );
    	  }
    	if ( $query->is_page( 'archiv' ) ) {
          $query->set( 'posts_per_page', 24 );
        }
    }

    no white screen with it, but it displays also 24 instead of 12 post on my home/blogpage. (btw: i configured wordpress to display 12 posts, but with the code-snippet this number has also no effect…)

    thanks again for your help!
    horst

    #746112
    Tom
    Lead Developer
    Lead Developer

    Strange – I just made an adjustment to my code, can you give it another shot?

    #746284
    horst

    thanks tom, the new code works perfectly!

    i have a small other problem (on a different site running GP as well) obviously because of the migration from the local machine to the live-server: there are two links of images referring to localhost (in the header), but i cant find where to change them.

    should i open a new support ticket?

    thanks for you help!

    #746322
    Leo
    Staff
    Customer Support

    Gonna take a blind guess here…check mobile header logo and navigation logo:
    https://docs.generatepress.com/article/mobile-header/
    https://docs.generatepress.com/article/navigation-logo/

    If not new topic please πŸ™‚

    #747593
    horst

    thanks again tom & leo,

    eventhough there where no entries in the mobile header with navigation logo (no image selected) i enabled it, disabled it, set a new image (from the server), deleted it.

    after that: and no more localhost entries in the code.

    thanks a million, and what a great support.

    all problems solved.

    best, horst

    #747975
    Leo
    Staff
    Customer Support

    Glad we could help πŸ™‚

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