query_posts() und pagination

Ein Tip von StylizedWeb:

As the title says when you are using a query_posts() to exclude, include categories or what ever you want pagination dosen’t work it shows same posts on every page (This is for all pages that use query_posts not just index, so it’s for templates etc…) (…) How to fix it? To get proper pagination with query_posts() we need to recreate it through the ‘paged’ parameter or query. Best way to do this is to ask WordPress for the “page” we happen to be on, and use that as our ‘paged’ value. There’s the code for it


<?php if (have_posts()) : ?>

 <?php query_posts("category_name=somecat"); ?>

 <?php while (have_posts()) : the_post(); ?>

replace with

<?php if (have_posts()) : ?>

 <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; query_posts("category_name=somecat&paged=$paged"); ?>

 <?php while (have_posts()) : the_post(); ?>

Possibly related posts (automatically generated)