Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 580127
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:26:23+00:00 2026-05-13T14:26:23+00:00

I have a page that lists over 100 items and I need to dynamically

  • 0

I have a page that lists over 100 items and I need to dynamically add a name=”” tags to the beginning of each new section of items that starts with the next alphabet.

For example:

<a name="a"></a>
<h1>Amazon River</h1>

<h1>Arrow Heads</h1>

<a name="b"></a>
<h1>Bear Claws</h1>

<h1>Bee Traps</h1>

<h1>Dodge Ball</h1>

<a name="f"></a>
<h1>Football Players</h1>

<h1>Fig Newtons</h1>

....

<a name="y"></a>
<h1>Yorktown</h1>

<h1>Yikes</h1>

<a name="z"></a>
<h1>Zebra</h1>

<h1>Zoo Mobile</h1>

I am only familiar w/ php, somewhat familiar w/ javascript, not sure what one it would take to accomplish this.

I will type out the “code” in theory, so you have an idea of what I want to accomplish

$letter = range(a-z);

if($title == first_letter_character($letter)) {
   print '<a name="'.$letter.'"></a>';
   $letter++; // goes to next letter in range
}

Also, there may be some letters that may not have an item.

Any help is appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T14:26:23+00:00Added an answer on May 13, 2026 at 2:26 pm

    It’s a hard call – the <a name="D"></a> doesn’t add a whole lot semantically to the document, so I’d be tempted to accomplish it in Javascript and keep the base markup clean. However, the resulting functionality yoursite.com/directory#D should function without JS, so using JS to enable it seems like a poor option. In the end, I’d include the tags in the markup via PHP, which is my default when in doubt.

    I assume you’ve got something like this, printing out your items

    <?php
    $items = array(......); // populated via database?
    
    foreach ($items as $item) {
      echo '<a href="<?= $item->url ?>"><?= htmlentities($item->name) ?></a>
    }
    ?>
    

    I would make the following modifications

    <?php
    $items = array(......); // populated via database?
    
    $last_letter = 0;
    
    foreach ($items as $item) {
      $letter = strtoupper($item->name[0]); // capitalized first letter
      if ($letter != $last_letter) {
        // not the same letter as last item
        echo '<a name="', $letter, '"></a>'; // <a name="A"></a>
        $last_letter = $letter;
      }
    
      echo '<a href="', $item->url, '">', htmlentities($item->name), '</a>';
    }
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form with over 100 list items that I must reorder on
I have a page where it allows users to add new ul dynamically using
I have a HAML page that lists some links to delete things that looks
I have a page (below) that has a datagrid that lists item's returned from
I have a page that, depending on input from a previous page, lists a
I have a page that displays a list of tickets. On each of these
I have a page ItemList that shows a list of items using div's. After
I have a page that lists content that are contained in a div with
I have a page that displays a list with a of elements with a
I have a web page that displays a list of documents stored on the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.