sunnykumar Posted August 6, 2014 Share Posted August 6, 2014 (edited) Hi, Can any one help me wit the pagination in android mobile App Pls find the attached file for full code As per the below coe it displays only 40 posts but i have around 500 posts. I can increse function add_query_vars($public_query_vars) { $public_query_vars[] = $this->namespace.'_p'; return $public_query_vars; } $args = array( 'post_type' => 'post', 'post_status' => 'publish', 'category__in' => $categories, ); if ($wp->query_vars[$this->namespace.'_p'] == 1){ $args['posts_per_page'] = 10; $args['offset'] = 0; }else{ $args['posts_per_page'] = 40; $args['offset'] = 10; } $posts = get_posts($args); I have tried but i am getting only 210 posts.only if i increse the post_per_page more than 70 in mobile android app it shows loding $args = array( 'post_type' => 'post', 'post_status' => 'publish', 'category__in' => $categories ); if ($wp->query_vars[$this->namespace.'_p'] == 1){ $args['posts_per_page'] = 70; $args['offset'] = 0; } if ($wp->query_vars[$this->namespace.'_p'] == 2){ $args['posts_per_page'] = 140; $args['offset'] = 70; } if ($wp->query_vars[$this->namespace.'_p'] == 3){ $args['posts_per_page'] = 210; $args['offset'] = 140; } $posts = get_posts($args); wp-app-maker.php Edited August 7, 2014 by mac_gyver fixed color highlighting Quote Link to comment https://forums.phpfreaks.com/topic/290309-pagination-with-offset-and-post-per-page/ Share on other sites More sharing options...
mac_gyver Posted August 7, 2014 Share Posted August 7, 2014 if ($wp->query_vars[$this->namespace.'_p'] == 1){ $args['posts_per_page'] = 10; $args['offset'] = 0; }else{ $args['posts_per_page'] = 40; $args['offset'] = 10; } the meaning of that code is: if you are on page 1 of the pagination, show 10 posts per page, start with the first overall post. if you are not on page 1 of the pagination, show 40 posts per page, start with the 10'th overall post (i.e. skip the 10 that were displayed on page 1.) this was done so that the first page shows less total information, resulting in pagination with two different number of posts per page, i.e. 10 on the first page, 40 on all other pages. you would not add code for each possible page. you would only change that code if you want to alter the number of posts per page, i.e. to make all pages have the same number of posts per page or to change the number of posts on the first page to be for example 5, while the number of posts on the rest of the pages are 40 per page. here is the documentation for the $args parameters (the Pagination Parameters are about half-way down on the page) - http://codex.wordpress.org/Class_Reference/WP_Query#Parameters if your pagination isn't working, there's some other problem then the specific code in your post above. Quote Link to comment https://forums.phpfreaks.com/topic/290309-pagination-with-offset-and-post-per-page/#findComment-1487064 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.