• Resolved AKNL

    (@aknl)


    Hi all, i’m builing up a page where want to show only posts with custom field ‘spot’ filled in, from all available categories and show below this post all other posts as links from the same category. I’m using the ‘spot’ marked post as a information post about the category and with the related code I show all other posts in the same category as link. This all works fine, below the code I use:

    [code moderated - please follow the forum guidelines for posting code]

    The problem starts when I want to put pagination into it. When I add
    'posts_per_page' => 2 to the query the whole pagination screws up, because the related posts are also counted as a post and that's not the intention. Is there a way to show the related posts, but outside the main query? And have 2 'spot' marked posts with all releated posts per page?

    Below what I want

    PAGE 1

    SPOT POST in Category 1
    RELATED POST in Category 1
    RELATED POST in Category 1

    SPOT POST in Category 2
    RELATED POST in Category 2
    RELATED POST in Category 2
    RELATED POST in Category 2
    RELATED POST in Category 2
    RELATED POST in Category 2
    RELATED POST in Category 2

    PAGE 2

    SPOT POST in Category 3
    RELATED POST in Category 3
    RELATED POST in Category 3
    RELATED POST in Category 3
    RELATED POST in Category 3

    SPOT POST in Category 4
    RELATED POST in Category 4
    RELATED POST in Category 4

    ETC.

    Hope someone can put me in the right direction, thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter AKNL

    (@aknl)

    I’m using ‘cat=-1’ because since ID 1 is for posts I want to exclude from being showcased at this point.

    Thread Starter AKNL

    (@aknl)

    Downsized my query, looks like posts_per_page is totally ignored. Anyone got an idea on how to fix this? I need to display 2 sticky posts per page.

    <?php query_posts(array('posts_per_page' =>2, 'paged' => get_query_var('page'), 'post__in'=>get_option('sticky_posts'))); ?>
    
    			<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    
    						<?php the_content(''); ?>
    
            <?php endwhile; ?>
    
            <?php else : ?>
    
            <?php endif; ?>
    
                <span class="older"><?php next_posts_link('« Older Entries'); ?></span>
                <span class="newer"><?php previous_posts_link('Newer Entries »'); ?></span>
    Thread Starter AKNL

    (@aknl)

    easy as

    Got it <?php query_posts('posts_per_page=2' . '&paged=' . get_query_var('paged')); ?> <?php if (have_posts()) : ?> <?php while (have_posts()) : the_post(); ?>

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Pagination with query_posts not working’ is closed to new replies.