Theme Function: Posts per page, & category exclude.
-
Hello!
I am having an issue getting my categories to be effectively hidden from the home page…
I’m not sure why the code isn’t working, but I think I might possibly have some coding conflict.
in my Theme Functions, I have the following:
function limit_posts_per_page() { if ( is_home() ) return 9; else return 99; // default: 99 posts per page }
And also:
add_filter('pre_option_posts_per_page', 'limit_posts_per_page'); function limit_posts_per_archive_page() { if ( is_category() ) set_query_var('posts_per_archive_page', 99); // or use variable key: posts_per_page } add_filter('pre_get_posts', 'limit_posts_per_archive_page'); function my_home_query( $query ) { // not an admin page and is the main query if (!is_admin() && $query->is_main_query()){ if(is_home()){ //cat=-94, -158"."&posts_per_page=9 $query->set('cat', -94, -158); $query->set('posts_per_page', 9); } } } add_action( 'pre_get_posts', 'my_home_query' );
If anyone could help me with this, it would be greatly appreciated!
Thank you in advance!
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Theme Function: Posts per page, & category exclude.’ is closed to new replies.