How about this? Let's go and test to be sure :)
<?php $new_get = $_GET; <a class="page-numbers" href="?<?php echo $new_get_string; ?>"> <?php echo $i ?> </a>
Also note that the entire $href bit is not needed. If you run href with ? , the browser will apply the query string to the current path.
I bet you are going to get hung up, so the version here is optimized for creating 10,000 links to page numbers. My tests put it somehow a little faster with a large number of links, since you are just doing string concatenation and not a complete assembly of HTTP requests, but this may not be enough to worry. The difference is only very important when there are five or six GET parameters, but when there is, this strategy completes after about half the time on my machine.
<?php $pageless_get = $_GET; // clone the GET array unset($pageless_get['pagenum']); // remove the pagenum parameter $pageless_get_string = http_build_query($pageless_get); // create the foo=bar&bar=baz string for($i = 0; $i < 10000; $i++): // append the pagenum param to the query string $page_param = "pagenum=$i"; if($pageless_get_string) { $pageful_get_string = "$pageless_get_string&$page_param"; } else { $pageful_get_string = $page_param; } ?> <a class="page-numbers" href="?<?php echo $pageful_get_string; ?>"> <?php echo $i ?> </a> <?php endfor ?>
source share