- This topic has 8 replies, 2 voices, and was last updated 3 years, 10 months ago by David.
-
AuthorPosts
-
June 1, 2020 at 10:46 am #1310162Pavla
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 notBlog Page
Exclude pages (I use categories for pages because of dynamic widgets and other things)
Exclude some categories from main blog page
Random posts orderI 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!
June 1, 2020 at 3:52 pm #1310417TomLead DeveloperLead DeveloperHi 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!
June 2, 2020 at 2:42 am #1310872Pavlaok! 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?
June 2, 2020 at 5:11 am #1311003DavidStaffCustomer SupportHi there,
you can set the excerpt to
0
in Customizer > Layout > BlogJune 2, 2020 at 3:14 pm #1311855Pavlaexcerpt: i did that but it doesn’t work, still showing it.
June 3, 2020 at 2:39 am #1312184DavidStaffCustomer SupportAre you using Manual Excerpts or Read More on some of your posts ? If so the auto excerpt does not apply.
June 7, 2020 at 8:37 am #1318094Pavlaok perfect that made it, thanks!
June 7, 2020 at 8:37 am #1318095Pavlaclosing
June 7, 2020 at 10:02 am #1318195DavidStaffCustomer SupportYou’re welcome
-
AuthorPosts
- You must be logged in to reply to this topic.