Jump to content

Recommended Posts

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 by mac_gyver
fixed color highlighting
            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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.