• Resolved jrcollins

    (@jrcollins)


    Can anyone explain how the “paged” and “offset” variables work in relation to the following block of code?

    <?php
    		$catpage = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1;
                $catnum = 3;
                $offset = ($catnum * $catpage) - 3;
    
    		$cat = get_category( get_query_var( 'cat' ) );
    		$cat_id = $cat->cat_ID;
    		$child_categories=get_categories(
    		array(
            'parent' => $cat_id,
    		'orderby' => 'id',
            'order' => 'DESC',
            'hide_empty' => '0',
            'number' => $catnum,
            'offset' => $offset,
            'paged' => $catpage
            // Uncomment the below line if you want empty category to appear on the list.
            // 'hide_empty'   => 0
        )
    );
    ?>
Viewing 1 replies (of 1 total)
  • Thread Starter jrcollins

    (@jrcollins)

    Ok, after some more research I realize it’s actually quite simple. The offset value tells the current page (given by the “paged” variable”) how many entries to ignore. In the example above, if the current page being viewed is page 3, the offset value is “6” which means that the current page will ignore the first 6 posts.

Viewing 1 replies (of 1 total)
  • The topic ‘Pagination offset and paged variables’ is closed to new replies.