[Resolved] Customise Category Pages and Blog page

Home Forums Support Customise Category Pages and Blog page

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #1310162
    Pavla

    Hi! I need to customise various Category pages and the main blog page.

    What I need to achieve is:

    Category pages

    Random posts order
    Exclude pages (I use categories for pages because of dynamic widgets and other things)
    Control how many posts are showed on the first page
    Posts in columns or not

    Blog Page
    Exclude pages (I use categories for pages because of dynamic widgets and other things)
    Exclude some categories from main blog page
    Random posts order

    I guess i could achieve it somehow with filters?

    I also saw some sidebar errors on different category pages, which have the same structure.
    e.g. ….category/empresas/hoteles/ the sidebar is sliding down, but in …/category/empresas/restaurantes/ its perfect.

    Thank you!

    #1310417
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    Changing the posts per page is quite complex because of pagination: https://wordpress.stackexchange.com/questions/155758/have-different-number-of-posts-on-first-page

    For the rest, you could try something like this:

    add_action( 'pre_get_posts', function( $query ) {
        if ( is_admin() || ! $query->is_main_query() ) {
             return;
        }
    
        if ( $query->is_category() ) { // Category pages.
            $query->set( 'orderby', 'rand' ); // Random order
            $query->set( 'post_type', array( 'post', 'another-post-type', 'something-else' ) ); // What post types to include
        }
    
        if ( $query->is_home() ) { // Blog page.
            $query->set( 'orderby', 'rand' ); // Random order
            $query->set( 'post_type', array( 'post', 'another-post-type', 'something-else' ) ); // What post types to include
            $query->set( 'cat', '-10' ); // Exclude category 10
        }
    } );

    For columns, this should help: https://docs.generatepress.com/article/using-columns-in-the-blog/#adding-columns-to-your-custom-post-type

    If your sidebar is broken (moving down the page), it typically means you have some broken HTML on the page. So an opening element (<div> for example) without a closing element (</div>).

    Hope this helps!

    #1310872
    Pavla

    ok! i’ll try that! and can i remove the excerpts completely from the blog page and the category page so i have only featured image, title and meta tags of categories?

    #1311003
    David
    Staff
    Customer Support

    Hi there,

    you can set the excerpt to 0 in Customizer > Layout > Blog

    #1311855
    Pavla

    excerpt: i did that but it doesn’t work, still showing it.

    #1312184
    David
    Staff
    Customer Support

    Are you using Manual Excerpts or Read More on some of your posts ? If so the auto excerpt does not apply.

    #1318094
    Pavla

    ok perfect that made it, thanks!

    #1318095
    Pavla

    closing

    #1318195
    David
    Staff
    Customer Support
Viewing 9 posts - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.