• I’m trying to make a pagination, but it’s not working. The second page aren’t showing any content. What am I doing wrong?

    <?php $parent = $post->ID; ?>
    
    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $args = array(
      'posts_per_page' => 4,
      'paged' => $paged,
      'post_parent' => $parent,
      'post_type' => $page
    );
    
    query_posts($args);
    ?>
    
    <?php while (have_posts()) : the_post(); ?>
    
    <li><a href="<?php the_permalink(); ?>">
    <?php the_post_thumbnail("thumbnail"); ?><br />
    <?php the_title(); ?></a></li>
    
    <?php endwhile; ?>
    </ul>	
    
    <div class="pagination">
        <div class="nav-previous alignleft"><?php next_posts_link( 'Older posts' ); ?></div>
    <div class="nav-next alignright"><?php previous_posts_link( 'Newer posts' ); ?></div></div>
    
    <?php wp_reset_query(); ?>
    </div>
Viewing 3 replies - 1 through 3 (of 3 total)
  • hello. sorry I am a bit of noob to PHP, but I have enabled pagination by:

    1. Adding this code to functions.php:
    2. function pagination($pages = '', $range = 4)
      {
           $showitems = ($range * 2)+1;  
      
           global $paged;
           if(empty($paged)) $paged = 1;
      
           if($pages == '')
           {
               global $wp_query;
               $pages = $wp_query->max_num_pages;
               if(!$pages)
               {
                   $pages = 1;
               }
           }   
      
           if(1 != $pages)
           {
               echo "<div class=\"pagination\"><span>Page ".$paged." of ".$pages."</span>";
               if($paged > 2 && $paged > $range+1 && $showitems < $pages) echo "<a href='".get_pagenum_link(1)."'>? First</a>";
               if($paged > 1 && $showitems < $pages) echo "<a href='".get_pagenum_link($paged - 1)."'>? Previous</a>";
      
               for ($i=1; $i <= $pages; $i++)
               {
                   if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems ))
                   {
                       echo ($paged == $i)? "<span class=\"current\">".$i."</span>":"<a href='".get_pagenum_link($i)."' class=\"inactive\">".$i."</a>";
                   }
               }
      
               if ($paged < $pages && $showitems < $pages) echo "<a href=\"".get_pagenum_link($paged + 1)."\">Next ?</a>";
               if ($paged < $pages-1 &&  $paged+$range-1 < $pages && $showitems < $pages) echo "<a href='".get_pagenum_link($pages)."'>Last ?</a>";
               echo "</div>\n";
           }
      }
    3. adding this code to index.php, right after <?php endwhile; ?> :
      <?php if (function_exists("pagination")) {
          pagination($additional_loop->max_num_pages);
      } ?>

      try it, it should work. and here’s the css if you need to customize it :

      .pagination {
          clear:both;
          overflow:hidden;
          font-size:16px;
          line-height:18px;
      }
      
      .pagination span, .pagination a {
          display:block;
          float:left;
          margin: 2px 2px 2px 0;
          padding:6px 9px 5px 9px;
          text-decoration:none;
          width:auto;
          color:#666666;
          background: #D8D8D8;
          transition: All .3s ease-in-out;
      }
      
      .pagination a:hover{
          color:#fff;
          background: #19BA7C;
      }
      
      .pagination .current{
          padding:6px 9px 5px 9px;
          background: #19BA7C;
          color:#fff;
      }

    Thread Starter Linosa

    (@linosa)

    Na, not workin.

    Thread Starter Linosa

    (@linosa)

    Any ideas?

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Pagination not working’ is closed to new replies.