# Pagination issue in DIVs

**URL:** <https://www.phphelp.com/t/pagination-issue-in-divs/15540>\
**Category:** Help with WordPress\
**Created:** [January 13, 2012, 9:29pm UTC](https://www.phphelp.com/t/pagination-issue-in-divs/15540 "2012-01-13T21:29:28Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://www.phphelp.com/uploads/default/original/2X/2/243e9ed5d93c5653ce3186f18df16e019ce38445.png) [@system](https://www.phphelp.com/u/system)\
**Post date:** [January 13, 2012, 9:29pm UTC](https://www.phphelp.com/t/pagination-issue-in-divs/15540/1 "2012-01-13T21:29:28Z")

</div>

Hi,  
I’m having an issue with some PHP code for my wordpress sidebar. It is a secondary loop that displays recent posts with pagination. I’ve got the basics working (ie, it pulls the content, and paginates)… but, I want to modify things ever so slightly to try and get the pagination numbers/links sitting in their own div so they don’t scroll with the main content. I thought i had it figured out, but, no such luck. as soon as I move things to the new div, the pagination/navigation stops functioning.Does anyone see a simple way around this?

Line 27 is where I tried closing my scrolling DIV and Line 28 is opening a new one for the pagination. It works… but it seems to totally kill the connection between the posts and the paging. It still shows the numbers, and even shows the links in the source code… but, nothing in the new div is clickable.

Here is code.

[php]

## Latest Posts

\<?php $sql = "SELECT p.\* from $wpdb-\>posts p WHERE p.post\_type = 'post' AND p.post\_status = 'publish' ORDER by p.post\_date DESC"; $mypages = $wpdb-\>get\_results($sql); if ($mypages) : $limit = 5; // The number of posts per page $range = 3; // The number of page links to show in the middle $mypage = (isset($\_GET['mypage'])) ? $mypage = $\_GET['mypage'] : 1; $start = ($mypage - 1) \* $limit; for ($i=$start;$i\<($start + $limit);++$i) { if ($i \< sizeof($mypages)) { // Process each element of the result array here $post = $mypages[$i]; setup\_postdata($post); echo get\_the\_post\_thumbnail($page-\>ID, 'thumbnail'); echo '
### ';the\_title();echo '
'; echo the\_excerpt(); echo'read more...'; } } echo '
'; // End Scrollables echo '
'; // Start Pagination echo \_mam\_paginate(sizeof($mypages),$limit,$range); else: echo '
### Sorry, There are no Pages to list
'; endif;?\>

\<?php function \_mam\_paginate($numrows,$limit=10,$range=7) { $pagelinks = "
"; $currpage = $\_SERVER['PHP\_SELF'] . "?" . $\_SERVER['QUERY\_STRING']; if ($numrows \> $limit) { if(isset($\_GET['mypage'])){ $mypage = $\_GET['mypage']; } else { $mypage = 1; } $currpage = $\_SERVER['PHP\_SELF'] . "?" . $\_SERVER['QUERY\_STRING']; $currpage = str\_replace("&mypage=".$mypage,"",$currpage); // Use this for non-pretty permalink $currpage = str\_replace("?mypage=".$mypage,"",$currpage); // Use this for pretty permalink if($mypage == 1){ $pagelinks .= "&laquo PREV "; }else{ $pageprev = $mypage - 1; $pagelinks .= "&laquo PREV "; } $numofpages = ceil($numrows / $limit); if ($range == "" or $range == 0) $range = 7; $lrange = max(1,$mypage-(($range-1)/2)); $rrange = min($numofpages,$mypage+(($range-1)/2)); if (($rrange - $lrange) \< ($range - 1)) { if ($lrange == 1) { $rrange = min($lrange + ($range-1), $numofpages); } else { $lrange = max($rrange - ($range-1), 0); } } if ($lrange \> 1) { $pagelinks .= " [1] "; if ($lrange \> 2) $pagelinks .= "&nbsp;...&nbsp;"; } else { $pagelinks .= "&nbsp;&nbsp;"; } for($i = 1; $i \<= $numofpages; $i++){ if ($i == $mypage) { $pagelinks .= " [$i] "; } else { if ($lrange \<= $i and $i \<= $rrange) { $pagelinks .= " [" . $i . "] "; } } } if ($rrange \< $numofpages) { if ($rrange \< $numofpages - 1) $pagelinks .= "&nbsp;...&nbsp;"; $pagelinks .= " [" . $numofpages . "] "; } else { $pagelinks .= "&nbsp;&nbsp;"; } if(($numrows - ($limit \* $mypage)) \> 0){ $pagenext = $mypage + 1; $pagelinks .= " NEXT »"; } else { $pagelinks .= " NEXT »"; } } $pagelinks .= "
"; return $pagelinks; } ?\>

[/php]

If it matters, I’m just checking the site locally using MAMP at the moment.

Thank you!
