0

I am trying to get a simple navigation to work, it works when I don't use offset in the arguments. but I like to do something special with the first post

$paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;

$args = array(
    'posts_per_page' => '6',
    'cat' => 5,
    'orderby' => 'date',
    'order' => 'DESC',
    'paged' => $paged
);`

So for these I add

$paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;

$args = array(
    'offset' => 1, //<---
    'posts_per_page' => '6',
    'cat' => 5,
    'orderby' => 'date',
    'order' => 'DESC',
    'paged' => $paged
);

But with offset the post are not returning correctly just the first 6???

1

If you sets a manual offset value, pagination will not function because that value will override WordPress's automatic adjustment of the offset for a given page. In order to use an offset in WordPress queries without losing WordPress's pagination features, you will need to manually handle some basic pagination calculations.

For example you can use this bellow code

$paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
$offset = 1;
$ppp = 6;
$page_offset = $offset + ( ($paged-1) * $ppp );

$args = array(
    'offset' => $page_offset,
    'posts_per_page' => $ppp,
    'cat' => 5,
    'orderby' => 'date',
    'order' => 'DESC',
    'paged' => $paged
);

Try that, then let me know the result. Note: Follow this https://codex.wordpress.org/Making_Custom_Queries_using_Offset_and_Pagination

  • @Souvik_sikdar seems to work like a charm Tx, I am rereading to see how you managed the $page_offset – alex Aug 9 '18 at 13:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.