Next and Prev page

3 posts by 2 authors in: Forums > CMS Builder
Last Post: March 11, 2013   (RSS)

By KCMedia - March 8, 2013

Hi guys

have this piece of code that does a nice page numbers how can i make this work with normal page code numbers

this is the code i want to use.

        <div class="row-fluid">
          <div class="pagination pagination-small pagination-centered offset1 span10">
            <ul>
              <li class="disabled">
                <a href="#">
                  <i class="icon-angle-left"></i>
                </a>
              </li>
              <li class="active">
                <a href="#">1</a>
              </li>
              <li>
                <a href="#">2</a>
              </li>
              <li>
                <a href="#">3</a>
              </li>
              <li>
                <a href="#">
                  <i class="icon-angle-right"></i>
                </a>
              </li>
            </ul>
          </div>
        </div>


and this is the cmsb code

                <!-- STEP3: Display Page Links (Paste anywhere below "Load Record List") -->
                <?php if ($blogMetaData['prevPage']): ?>
                  <a href="<?php echo $blogMetaData['prevPageLink'] ?>">&lt;&lt;  prev</a>
                <?php else: ?>
                  &lt;&lt; prev
                <?php endif ?>
            
                - page <?php echo $blogMetaData['page'] ?> of <?php echo $blogMetaData['totalPages'] ?> -
            
                <?php if ($blogMetaData['nextPage']): ?>
                  <a href="<?php echo $blogMetaData['nextPageLink'] ?>">next &gt;&gt;</a>
                <?php else: ?>
                  next &gt;&gt;
                <?php endif ?>
              <!-- /STEP3: Display Page Links -->

Thanks



Craig

KC Media Solutions

www.kcmedia.biz

Hi Craig,

You'll have to write something custom to get this working, this is how I would do it:

<?php 
 // load records from 'blog'
  list($blogRecords, $blogMeta) = getRecords(array(
    'tableName'   => 'blog',
    'perPage'     => '10',
    'loadUploads' => true,
    'allowSearch' => false,
  ));

?>


          <div class="row-fluid">
          <div class="pagination pagination-small pagination-centered offset1 span10">
            <ul>
              <li class="disabled">
                <a href="<?php echo $blogMeta['prevPageLink']; ?>">
                  <i class="icon-angle-left"></i>
                </a>
              </li>
              <?php foreach( range('1',$blogMeta['totalPages']) as $pageNumber): ?>
                <li <?php if($pageNumber == $blogMeta['page']): ?>class="active"<?php endif; ?>>
                  <a href="/pageLink.php?page=<?php echo $pageNumber; ?>"><?php echo $pageNumber; ?></a>
                </li>
              <?php endforeach; ?>
              <li>
                <a href="<?php echo $blogMeta['nextPageLink']; ?>">
                  <i class="icon-angle-right"></i>
                </a>
              </li>
            </ul>
          </div>
        </div>

This is just example code, so you might have to change the name of some of the variables used. (You'll probably have to replace $blogMeta with $blogMetaData, and replace pageLink.php with the page name).

The range function generates an array of numbers the same size as the number of pages, then the foreach loops through the array generating the number list elements. 

Let me know if you have any questions.

Thanks!

Greg

Greg Thomas







PHP Programmer - interactivetools.com