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. 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

  • Use Markdown, and it will escape the code for you, like `<div class="cool">`.
  • Use triple-backticks for blocks of code.
    ``` 
    <div>
      <h1>multi-line block of code</h1>
      <span>be cool yo.</span>
    </div>
    ```
  • Otherwise, escape your code, like <code>&lt;div class="cool"&gt;</code>. Markdown is just easier though.

Current ye@r *

*May or may not contain any actual "CSS" or "Tricks".