• Resolved webipsum

    (@ipsum)


    Hi.

    WP_Pagenavi: Works:

    <div id="content">
    	<?php $query = new WP_Query('cat=8&posts_per_page=6' . '&paged=' . $paged); ?>
    	<?php if ($query->have_posts()) : while($query->have_posts()) : $query->the_post(); ?>
    	<div class="list_posts">
    		<?php the_content(); ?>
    	</div><!-- list_posts -->
    	<?php endwhile; ?>
    		<?php if(function_exists('wp_pagenavi')) : wp_pagenavi(array( 'query' => $query )); endif; ?>
    	<?php else : ?>
    	<?php endif; ?>
    </div><!-- content -->

    But if I include: offset, don’t works:

    <?php $query = new WP_Query('cat=8&posts_per_page=6$offset=3' . '&paged=' . $paged); ?>

    Please, any tips?.

    Tks a lot.

    {ipsum}

Viewing 15 replies - 1 through 15 (of 16 total)
  • pagination does generally not work with using ‘offset’ in the query.

    please explain what you are trying to achieve; there might be a different solution.

    Thread Starter webipsum

    (@ipsum)

    alchymyth.
    Display posts: cat = 4,6,8,9 and posts_per_page = 8 and offset = 3, with pagination (wp-pagenavi).

    <?php get_header() ?>
    <div id="content">
    <?php $query = new WP_Query('cat=4,6,8,9&posts_per_page=8&offset=3' . '&paged=' . $paged); ?>
    	<?php if ($query->have_posts()) : while($query->have_posts()) : $query->the_post(); ?>
    		<h3><a href="<?php the_permalink() ?>" rel="bookmark" title="Leia: <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h3>
    	<?php endwhile; ?>
    		<?php if(function_exists('wp_pagenavi')) : wp_pagenavi(array( 'query' => $query )); endif; ?>
    	<?php else : ?>
    	<?php endif; ?>
    </div><!-- content -->
    <?php get_footer() ?>

    Thank you for your attention.

    {ipsum}

    Thread Starter webipsum

    (@ipsum)

    alchymyth.
    Do you have any additional information?
    Tks.

    Plugin Author scribu

    (@scribu)

    Sidenote: Adding {ipsum} to the end of each post is really distracting. Please stop doing that. We already know your user name is ‘ipsum’.

    Thread Starter webipsum

    (@ipsum)

    I’m sorry.
    Thank you for your comment.

    Plugin Author scribu

    (@scribu)

    Display posts: cat = 4,6,8,9 and posts_per_page = 8 and offset = 3, with pagination (wp-pagenavi).

    The question is: why do you want offset = 3? Are you displaying the first 3 posts differently?

    Thread Starter webipsum

    (@ipsum)

    Yes.
    index.php:
    1) display 3 most recent post (highlights).
    2) display others posts, without the 3 highlights (offset=3). With pagination.

    possibly get the three last posts (although this is an additional query); then use these three post ids to exclude them in your query;

    example:

    <?php
    $last_three = get_posts('cat=4,6,8,9&numberposts=3');
    $last_three_ids = array();
    if( $last_three ) foreach( $last_three as $last_post ) { $last_three_ids[] = $last_post->ID; }
    
    $query = new WP_Query(array('cat' => '4,6,8,9', 'post__not_in' => $last_three_ids, 'posts_per_page' => 8, 'paged' => get_query_var('paged') ) );  ?>

    this is supposed to replace:

    <?php $query = new WP_Query('cat=4,6,8,9&posts_per_page=8&offset=3' . '&paged=' . $paged); ?>

    edit:
    i didn’t have the latest info when i posted the above;

    if you run a query with the first three posts anyway, simply collect the post IDs in an array, to be used in the second query with the ‘post__not_in’ parameter.

    it might be useful, if you could paste the full code of your template into a http://pastebin.com/ and post the link to it here.

    there is also the other possibility to use only one loop with a counter to distinguish the first three posts, and use an if statement to display them differently (unsing the counter and the is_paged() conditional tag).

    Thread Starter webipsum

    (@ipsum)

    Pastebin, with the suggested changes (without layout (divs, etc.), for easy viewing.).
    http://pastebin.com/pQ5v5Jnb
    Selects perfectly, but does not perform paging.
    Thank you.

    try to add a ‘wp_reset_query()’ after the loop of the first three highlight posts (for instance in line 36 of your pastebin code);

    http://pastebin.com/XqNwsaa0

    Don’t even try this solution will not work due to the nature of paging. I was able to find a solution Here , just follow steps 1-3 and you should be good to go, I included my category filters by just adding a $myCat variable containing the categories I needed.. If you’ve gotten this far all of this should be pretty straight forward.

    Thread Starter webipsum

    (@ipsum)

    try to add a ‘wp_reset_query()’ after the loop of the first three highlight posts (for instance in line 36 of your pastebin code);

    alchymyth: You are the Master. πŸ™‚
    Worked perfectly.
    Thank you very much.

    overexposeddesign: I’ll read your tip. Tks.

    glad it worked πŸ˜‰

    this is just an example how helpful it is to share the full code of any templates with problems, as the actual cause could be somewhere else in the template.

    huh? NO way. I tried that and another similar solution that i deciphered from a Google translate that was in Japanese and couldn’t get to work. oi vay

    Hallo,
    I’ve two loops in a custom page template and I was raving about pagination hating offset disgrace.

    The numberpost filter solution is very clever, works like a charme.

    Thanks!

    -m.

Viewing 15 replies - 1 through 15 (of 16 total)
  • The topic ‘[Plugin: WP-PageNavi] wp_pagenavi does not work with offset?’ is closed to new replies.