WordPress.org

Ready to get started?Download WordPress

Forums

WP-Paginate (10 posts)

  1. meets
    Member
    Posted 1 year ago #

    hi every one

    i am using below code but pagination is not working on index paging it always showing same page. plz any one can help me.

    Thanks in advance.

    <?php
    //$recent_posts = wp_get_recent_posts();
    
    $header_posts = new WP_Query('posts_per_page=3&cat=6&offset=1' );
    if ($header_posts->have_posts()) :
    $i=0;
    while ($header_posts->have_posts()) : $header_posts->the_post();
    
    echo '<div class="leading-b left">';
    ?>
    		  <div class="top_img left"><a href="<?php the_permalink(); ?>">
                <?php
    								$images = get_children( array( 'post_parent' => $post->ID, 'post_type' => 'attachment', 'post_mime_type' => 'image', 'orderby' => 'menu_order', 'order' => 'ASC', 'numberposts' => 999 ) );
    								if ( $images ) :
    									$total_images = count( $images );
    									$image = array_shift( $images );
    									$image_img_tag = wp_get_attachment_image( $image->ID, 'thumbnail',$icon = false, $attr = 'style=width:144px;height:94px; float:left' );
    
    									echo $image_img_tag;
    							   endif; ?></a></div>
    					 <h2><a href="<?php the_permalink();?>"><?php the_title();?></a></h2>		   
    
    							  <span class="bor"><?php the_time('D') ;?> - <?php the_time('d') ;?> <?php the_time('M') ;?> </span> &nbsp;<span><?php the_excerpt();?></span>   <p> <?php ringgirl_post();?></p>
           <a href="<?php the_permalink();?>">(Read more...)</a>
    
    	   </div>
    	     <?php  endwhile; endif;?>
    		 	<?php twentyeleven_content_nav( 'nav-below' ); ?>
    		 <?php if(function_exists('wp_paginate')) {
        wp_paginate();
    } ?>
  2. Pioneer Valley Web Design
    Member
    Posted 1 year ago #

    Why is line 2 commented out?

    //$recent_posts = wp_get_recent_posts();

    the // means ignore this line...

  3. IMICreation
    Member
    Posted 1 year ago #

    you can try two things
    one is try resetting query with wp_reset_query(); after endif
    second is try inserting pagination after endwhile

  4. keesiemeijer
    moderator
    Posted 1 year ago #

    Pagination does not work if you use the offset parameter.

    if the 'offset' is used to avoid the first post to be shown twice, look into the methods of avoiding duplicate posts:

    http://codex.wordpress.org/The_Loop#Multiple_Loops_in_Action

  5. meets
    Member
    Posted 1 year ago #

    hi kees

    i am trying this but still same problem.

    <?php 
    
    $my_query = new WP_Query('category_name=fight&posts_per_page=3');
      while ($my_query->have_posts()) : $my_query->the_post();
      $do_not_duplicate = $post->ID; 
    
    echo '<div class="leading-b left">';
    ?>
    		  <div class="top_img left"><a href="<?php the_permalink(); ?>">
                <?php
    								$images = get_children( array( 'post_parent' => $post->ID, 'post_type' => 'attachment', 'post_mime_type' => 'image', 'orderby' => 'menu_order', 'order' => 'ASC', 'numberposts' => 999 ) );
    								if ( $images ) :
    									$total_images = count( $images );
    									$image = array_shift( $images );
    									$image_img_tag = wp_get_attachment_image( $image->ID, 'thumbnail',$icon = false, $attr = 'style=width:144px;height:94px; float:left' );
    
    									echo $image_img_tag;
    							   endif; ?></a></div>
    					 <h2><a href="<?php the_permalink();?>"><?php the_title();?></a></h2>		   
    
    							  <span class="bor"><?php the_time('D') ;?> - <?php the_time('d') ;?> <?php the_time('M') ;?> </span> &nbsp;<span><?php the_excerpt();?></span>   <p> <?php ringgirl_post();?></p>
           <a href="<?php the_permalink();?>">(Read more...)</a>
    
    	   </div>
    	     <?php  endwhile;?>
    
    				<?php twentyeleven_content_nav( 'nav-below' ); ?>
  6. meets
    Member
    Posted 1 year ago #

    @ Seacoast Web Design

    yes this line is comment.

  7. keesiemeijer
    moderator
    Posted 1 year ago #

    Try it with:

    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $my_query = new WP_Query('category_name=fight&posts_per_page=3&paged=' . $paged);

    I'm not sure if wp-paginate can be used for custom queries: http://wordpress.org/support/topic/wp-paginate-and-custom-queries?replies=16

  8. meets
    Member
    Posted 1 year ago #

    thanks it's work but it is always showing only two page in paging 1 2 not displaying 3 4 5 6 7 8. i am using wp paination plugin

  9. keesiemeijer
    moderator
    Posted 1 year ago #

    Try it with this:

    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $temp = $wp_query;
    $wp_query= null;
    $wp_query = new WP_Query();
    $args = array(
      'posts_per_page' => 3,
      'paged' => $paged,
      'category_name' => 'fight',
    );
    // $wp_query->query is equivalent to query_posts( //ARGS );
    $wp_query->query($args);
      while ($wp_query->have_posts()) : $wp_query->the_post();
      $do_not_duplicate = $post->ID; 
    
    echo '<div class="leading-b left">';
    ?>
    		  <div class="top_img left"><a href="<?php the_permalink(); ?>">
                <?php
    								$images = get_children( array( 'post_parent' => $post->ID, 'post_type' => 'attachment', 'post_mime_type' => 'image', 'orderby' => 'menu_order', 'order' => 'ASC', 'numberposts' => 999 ) );
    								if ( $images ) :
    									$total_images = count( $images );
    									$image = array_shift( $images );
    									$image_img_tag = wp_get_attachment_image( $image->ID, 'thumbnail',$icon = false, $attr = 'style=width:144px;height:94px; float:left' );
    
    									echo $image_img_tag;
    							   endif; ?></a></div>
    					 <h2><a href="<?php the_permalink();?>"><?php the_title();?></a></h2>		   
    
    							  <span class="bor"><?php the_time('D') ;?> - <?php the_time('d') ;?> <?php the_time('M') ;?> </span> &nbsp;<span><?php the_excerpt();?></span>   <p> <?php ringgirl_post();?></p>
           <a href="<?php the_permalink();?>">(Read more...)</a>
    
    	   </div>
    	     <?php  endwhile;?>
    
    				<?php twentyeleven_content_nav( 'nav-below' ); ?>
    <?php $wp_query = null; $wp_query = $temp; ?>
  10. meets
    Member
    Posted 1 year ago #

    its work but after two pages it's not displaying any thing. but there is data in 3 4 5 6 pages. shwoing error This is somewhat embarrassing, isn’t it?

Topic Closed

This topic has been closed to new replies.

About this Topic