Archived topic
Customise Category Pages and Blog page
8 replies · Started by Pavla on June 1, 2020
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!
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!
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?
Hi there,
you can set the excerpt to 0 in Customizer > Layout > Blog
excerpt: i did that but it doesn’t work, still showing it.
Are you using Manual Excerpts or Read More on some of your posts ? If so the auto excerpt does not apply.
ok perfect that made it, thanks!
closing
You're welcome