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. User Avatar
    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. User Avatar
    Robert
    Permalink to comment#

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

  3. User Avatar
    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. User Avatar
    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. User Avatar
    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. User Avatar
    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. User Avatar
    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 }

Submit a Comment

Posting Code

You may write comments in Markdown. This makes code easy to post, as you can write inline code like `<div>this</div>` or multiline blocks of code in triple backtick fences (```) with double new lines before and after.

Code of Conduct

Absolutely anyone is welcome to submit a comment here. But not all comments will be posted. Think of it like writing a letter to the editor. All submitted comments will be read, but not all published. Published comments will be on-topic, helpful, and further the discussion or debate.

Want to tell us something privately?

Feel free to use our contact form. That's a great place to let us know about typos or anything off-topic.

icon-closeicon-emailicon-linkicon-logo-staricon-menuicon-searchicon-staricon-tag