Highlight current page in navigation


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. <?php
  2. //page titles / page number
  3. $titles = array(
  4. 'Page Number 1' => '01',
  5. 'Page Number 2' => '02',
  6. 'Page Number 3' => '03'
  7. );
  8. //get current page
  9. $page = (!empty($_GET['page'])) ? $_GET['page'] : null;
  10. //write pages
  11. foreach($titles as $v => $k) {
  12. $h = ($k == $page) ? " style='background:yellow;'" : '';
  13. echo "<a href='?page=$k'$h>$v</a><br />\n";
  14. }
  15.  
  16. // If page is '?page=02', will print...
  17. //
  18. // <a href='?page=01'>Page Number 1</a>
  19. // <a href='?page=02' style='background:yellow;'>Page Number 2</a>
  20. // <a href='?page=03'>Page Number 3</a>
  21. ?>

URL: http://davidsword.ca/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.