WordPress.org

Ready to get started?Download WordPress

Forums

Query (by category name) + next/previous posts links (10 posts)

  1. backinthe90s
    Member
    Posted 2 years ago #

    hey,

    i made a template page, that should only display posts in the category "blog".

    i used <php query_posts('category_name=blog'); ?> which worked quite well.

    but now it does not work anymore beacuse page 2, 3, ... all display the same first 10 posts.

    i tried to fix it with this help: http://wordpress.org/support/topic/querying-all-posts?replies=12#post-679318

    now my code looks like this:

    <?php
    $limit = get_option('posts_per_page');
    $page = (get_query_var('page')) ? get_query_var('page') : 1;
    query_posts('category_name=blog' . '&showposts=' . $limit . '&paged=' . $page);
    $wp_query->is_archive = true; $wp_query->is_home = false;
    ?>

    and after the posts

    <?php
    		endwhile;
    		next_posts_link('Previous Posts');
    		previous_posts_link('Next Posts');
    		?>

    on the first page the link "previous posts" appears and page 2 works fine. but at the bottom of page 2 there is only another link "previous posts" and not "next posts" and the "previous posts" link on page 2 does not work. it does not link me to page 3...

    can somebody please help me?

    would be great.

    thanks

  2. keesiemeijer
    moderator
    Posted 2 years ago #

    Does it work when you only use this?

    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    query_posts('category_name=blog&paged=' . $paged);
  3. backinthe90s
    Member
    Posted 2 years ago #

    unfortunately this does not work. page 2 is the same as page 1. and link to page 3 still does not work. and there is also no next posts link

  4. keesiemeijer
    moderator
    Posted 2 years ago #

    Can you paste and submit the full code of the template file into a pastebin.com and post the link to it here? see the Forum Rules for posting code and using the pastebin.

  5. backinthe90s
    Member
    Posted 2 years ago #

    http://pastebin.com/mEmqJ2ZR

    thanks for your efforts, so far!

  6. keesiemeijer
    moderator
    Posted 2 years ago #

    I don't think you need the $wp_query->is_archive = true; $wp_query->is_home = false; code. And $limit is the default number of post to show per page, so you don't need that as well.

    Try it with this: http://pastebin.com/8rFGm9iw

    Is this a static front page?

  7. backinthe90s
    Member
    Posted 2 years ago #

    still does not work. just showing the same 10 posts on page 2. and the next posts link on page 2 is still missing. and previous link on page 2 still not linking to page 3 :(

    and yes it is a static front page!

    edit:
    i tried to use it as a normal page and when this page is not used as a front page, it works perfectly!

  8. keesiemeijer
    moderator
    Posted 2 years ago #

    Try it with this for your static front page: http://pastebin.com/nGjKSFRN

  9. backinthe90s
    Member
    Posted 2 years ago #

    GREAT!

    works perfectly!
    thank you so much for your efforts!!

  10. keesiemeijer
    moderator
    Posted 2 years ago #

    No problem. Glad you got it resolved.

Topic Closed

This topic has been closed to new replies.

About this Topic