Forums

[resolved] Category filtering (next and previous not working) (3 posts)

  1. constantin.chirila
    Member
    Posted 1 year ago #

    Hello there.
    First let me tell about what I have in mind. I want to create more of a website with the WordPress as a CMS. I have around 3 pages.On one it will show preview of the news posts the other one will show the full list of the posts and another page with some events. The problem(i think) is that i want to have next and previous buttons on all of them.
    Each of the page will show posts from different category. (something worth mentioning is that except the home page the other pages have different templates)

    So on the first page i used this category filtering technique:

    <?php query_posts($query_string . '&category_name=news&posts_per_page=2'); ?>
    <?php if(have_posts()) : while(have_posts()) : the_post(); ?>
    <a href="<?php the_permalink() ?>"><img src="<?php $thumb = get_post_custom_values('preview_img'); echo $thumb[0]; ?>" alt="<?php the_title(); ?>" /></a>
    <h1><a href="<?php the_permalink() ?>"> <?php the_title(); ?> </a></h1>
    <p class="meta"> posted by <?php the_author();?> on <?php the_date(); ?> </p>
    <?php excerpt('60'); ?>
    <?php endwhile; ?>
    <?php next_posts_link('Next>>'); ?>
    <?php previous_posts_link('<<Previous'); ?>
    <?php else : ?>
    I'm not sure what you're looking for.
    <?php endif; ?>

    This seams to work on the home page.
    But when i apply the exact same technique on the other pages won't work (it doesn't show anything only the page template) so i tried without $query_string meaning
    <?php query_posts('&category_name=news&posts_per_page=2'); ?>
    and now it shows me the last two posts but when i click next it doesn;t show the enxt posts, it still shows the first posts, so nothing is changing. The links are working cause they get me to the next page (i mean the link changes) just the posts doesnt change.

    Tried lots of googled solutions with no luck :(.

    If you need more info, let me know.

  2. alchymyth
    The Sweeper
    Posted 1 year ago #

    did yo try to include the 'paged' parameter to the query?

    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    query_posts('category_name=news&posts_per_page=2&paged='.$paged); ?>

    and if you use other queries before this one, you could additionally try to add a 'wp_reset_query();' before the above code

  3. constantin.chirila
    Member
    Posted 1 year ago #

    Damn.... it works like a charm.
    Thanks a million.

Topic Closed

This topic has been closed to new replies.

About this Topic