Show different number of posts in mobile landscape and portrait mode.
-
I want to show the different number of posts on my mobile according to its orientation. I am using this code
function set_posts_per_page( $query ) { $iphone = strpos($_SERVER['HTTP_USER_AGENT'],"iPhone"); $ipad = strpos($_SERVER['HTTP_USER_AGENT'],"iPad"); if(wp_is_mobile()) { if ($iphone == true) { $query->set( 'posts_per_page', 24 ); } else if ( $ipad == true) { $query->set( 'posts_per_page', 22 ); } else{ $query->set( 'posts_per_page', 10 ); } } else{ $query->set( 'posts_per_page', 24 ); } } add_action( 'pre_get_posts', 'set_posts_per_page' );
how to check moiles orientation with wp_is_mobile().
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Show different number of posts in mobile landscape and portrait mode.’ is closed to new replies.