2011-01-10 20 views
4

arbeitet Ich versuche Paginierung Arbeit mit dem folgenden Code zu machen, aber kein Glück:query_posts mit Paginierung nicht

$page = (get_query_var('paged')) ? get_query_var('paged') : 1; 
$args = array(
    'cat' => '5', 
    'post_type' => 'post', 
    'posts_per_page' => 6, 
    'paged' => $page, 
); 

query_posts($args); 

while(have_posts()) { 
    the_post(); ?> 
    <div class="project_item"> 
     <div class="dotted"> 
      <hr /> 
     </div> 
     <div class="project_thumb"><a href="<?php echo get_permalink(); ?>"><img src="<?php getCustomField('news_thumbnail'); ?>" /></a></div> 
     <div class="project_entry"><h4><a href="<?php echo get_permalink(); ?>"><?php getCustomField('news_title'); ?></a></h4> 
      <?php getCustomField('news_excerpt'); ?> 
      <a href="<?php echo get_permalink(); ?>" class="readmore">Read more..</a> 
     </div> 
    </div> 
<?php } 

wp_reset_query(); // Restore global post data 
+0

Sie können versuchen, dies unter http://wordpress.stackexchange.com zu fragen. – mercator

+0

Wie viele neue Stackexchange-Sites öffnen sich jede Woche? Vielen Dank! – redconservatory

Antwort

6

Ich brauche nur vorherige und nächste Links nach der Schleife hinzuzufügen:

<div class="navigation"> 
    <div class="alignleft"><?php previous_posts_link('&laquo; Previous') ?></div> 
    <div class="alignright"><?php next_posts_link('More &raquo;') ?></div> 
</div> 

Vollständiger Code:

<?php 
    $args = array(
        'cat' => '5', 
        'post_type' => 'post', 
        'posts_per_page' => 6, 
        'paged' => (get_query_var('paged') ? get_query_var('paged') : 1), 
        ); 

    query_posts($args); 

while (have_posts()) : the_post(); 
/* Do whatever you want to do for every page... */ 
?> 
    <div class="project_item"> 
     <div class="dotted"> 
      <hr /> 
     </div> 
     <div class="project_thumb"><a href="<?php echo get_permalink(); ?>"><img src="<?php getCustomField('news_thumbnail'); ?>" /></a></div> 
     <div class="project_entry"><h4><a href="<?php echo get_permalink(); ?>"><?php getCustomField('news_title'); ?></a></h4> 
      <?php getCustomField('news_excerpt'); ?> 
      <a href="<?php echo get_permalink(); ?>" class="readmore">Read more..</a> </div> 
     </div> 

     <?php 

endwhile; 
?><div class="navigation"> 
    <div class="alignleft"><?php previous_posts_link('&laquo; Previous') ?></div> 
    <div class="alignright"><?php next_posts_link('More &raquo;') ?></div> 
</div> 
<?php 
wp_reset_query(); // Restore global post data 
?> 
4

Hier ist die Lösung zu haben, es mit allen Paginierung Plugins arbeiten:

global $wp_query; 
query_posts(
    array_merge(
     array(
     'category__not_in' => 69, //ifu want to exclude some category 
     'posts_per_page' => 9 
     ), 
     $wp_query->query 
    ) 
);