Treehouse: Grow your CSS skills. Land your dream job.

Last updated on:

Quick Alphabetic Navigation

Could be useful for an address book style navigation.

<?php
foreach (range('a', 'z') as $char) {
 print '<a href="#' . $char . '">' . $char . '</a> | ';
}
?>

Comments

  1. Andy
    Permalink to comment#

    This is awesome! So simple, but such a good use of the range function.
    Would be good for a glossary or huge list of items.

  2. Robert
    Permalink to comment#

    Nice script !
    Add this and it becomes a nice $_Get[‘page’]‘ . $char . ‘

  3. Matthew
    Permalink to comment#

    Yeah please a working example of this would be great?!

    I often have clients request a way to index all pages and post in WordPress alphabetically or in many cases for their products in when running woocommerce.

    But any example would be great and I can take it from there :-)

  4. Robert
    Permalink to comment#

    I am sorry i took so long to reply here is the function for pagination using query count.
    function pagInate()
    {
    //HERE WE QUERY THE COUNT VARIABLE VALUE FROM TH DATABASE//
    $show = 10;
    $count = 123;//A TEST RESULT REMOVE AND REPLACE WITH QUERY COUNT FOR PRODUCTION//
    $limit = ($count / $show);
    //echo $limit;
    foreach (range(‘1′, ”.$limit.”) as $char)
    {
    //echo $limit;
    print ‘‘ . $char . ‘ | ‘;
    }

    }//end function
    //WE CALL THE FUNCTION//
    echo pagInate();

  5. Robert
    Permalink to comment#

    Pass the value as GET in this way or you can use POST method to.
    a href=”index.php?value= $char //Which in this case $char will return the values 1 through 12 for each new page to show the next 10 results. You will need to add either an isset($_POST or $_GET value to grab each passed $char.

  6. Robert
    Permalink to comment#

    And of course your query above this will be
    $page = isset($_GET[‘value’];
    LIMIT $page , 10 or $show either one as long as it is called before the query.

  7. Robert
    Permalink to comment#

    This may require some thought as to returning zero or a lessor value for $count result,, so you will need to add a condition that checks count for a value less than the $show of 10 and this will be something like–>
    if $count <= $show; { query any results }else{ query the count and fetch the LIMIT data and Do foreach }

Leave a Comment

Posting Code

We highly encourage you to post problematic HTML/CSS/JavaScript over on CodePen and include the link in your post. It's much easier to see, understand, and help with when you do that.

Markdown is supported, so you can write inline code like `<div>this</div>` or multiline blocks of code in in triple backtick fences like this:

```
<script>
  function example() {
    element.innerHTML = "<div>code</div>";
  }
</script>
```