Skip to content

Instantly share code, notes, and snippets.

@greenboyroy
Last active October 28, 2017 06:03
Show Gist options
  • Select an option

  • Save greenboyroy/757c345a5885293bde53 to your computer and use it in GitHub Desktop.

Select an option

Save greenboyroy/757c345a5885293bde53 to your computer and use it in GitHub Desktop.

Revisions

  1. greenboyroy revised this gist Feb 10, 2016. 2 changed files with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion glossary.php
    Original file line number Diff line number Diff line change
    @@ -41,7 +41,7 @@
    //reset $current_letter and display glossary, adding heading letters as required
    $current_letter = '';
    perch_content_custom('Glossary', [
    'template' => '_glossary_listing.html',
    'template' => 'glossary_listing.html',
    'sort' => 'title',
    'sort-order' => 'ASC',
    'each' => function($item) {
    File renamed without changes.
  2. greenboyroy renamed this gist Feb 10, 2016. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. greenboyroy revised this gist Feb 10, 2016. 2 changed files with 14 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions Alphabetical Pagination
    Original file line number Diff line number Diff line change
    @@ -19,6 +19,7 @@
    'sort-order' => 'ASC',
    'each' => function($item) {
    $word = strtoupper($item['title']);
    // if the first letter of the title is different to current_letter, it's new so add it to nav_arr
    if (strcmp($word[0], $GLOBALS['current_letter']) !== 0) {
    $my_letter = $GLOBALS['current_letter'] = is_numeric($word[0]) ? '0-9' : $word[0];
    $GLOBALS['nav_arr'][$my_letter] = '<a href="#glossary-'.$my_letter.'">'.$my_letter.'</a>';
    @@ -45,6 +46,7 @@
    'sort-order' => 'ASC',
    'each' => function($item) {
    $word = strtoupper($item['title']);
    // if the first letter of the title is different to current_letter, it's new so add it to the template
    if (strcmp($word[0], $GLOBALS['current_letter']) !== 0) {
    $item['letter'] = $GLOBALS['current_letter'] = is_numeric($word[0]) ? '0-9' : $word[0];
    }
    12 changes: 12 additions & 0 deletions _glossary_listing.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    <perch:before><div class="group"></perch:before>
    <perch:if exists="letter">
    <perch:if exists="perch_item_first"><perch:else /><a href="#top" class="glossary__top">Go to top</a></div><div class="group"></perch:if>
    <div class="glossary__letter">
    <h2 id="glossary-<perch:content id="letter" />"><perch:content id="letter" /></h2>
    </div>
    </perch:if>
    <div id="<perch:content id="slug" type="slug" for="title" />" class="glossary__item">
    <div class="glossary__term"><perch:content id="title" /></div>
    <div class="glossary__meaning"><perch:content id="desc" type="textarea" /></div>
    </div>
    <perch:after><a href="#top" class="glossary__top">Go to top</a></div></perch:after>
  4. greenboyroy revised this gist Feb 10, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Alphabetical Pagination
    Original file line number Diff line number Diff line change
    @@ -4,7 +4,7 @@
    // setup alphabet array for navigation
    // make array of letters in span tags
    $nav_arr = array(
    '0-9' => '<span class="glossary-letter">0-9</span>'
    '0-9' => '<span>0-9</span>'
    );
    for ($i = 65; $i <= 90; $i++) {
    $nav_arr[chr($i)] = '<span>'.chr($i).'</span>';
  5. greenboyroy revised this gist Feb 9, 2016. No changes.
  6. greenboyroy revised this gist Feb 9, 2016. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion Alphabetical Pagination
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,9 @@
    <?php
    // setup alphabet array for navigation
    // make array of letters in span tags
    $nav_arr = [];
    $nav_arr = array(
    '0-9' => '<span class="glossary-letter">0-9</span>'
    );
    for ($i = 65; $i <= 90; $i++) {
    $nav_arr[chr($i)] = '<span>'.chr($i).'</span>';
    }
  7. greenboyroy created this gist Feb 9, 2016.
    54 changes: 54 additions & 0 deletions Alphabetical Pagination
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,54 @@
    <main role="main" class="glossary">
    <div class="group">
    <?php
    // setup alphabet array for navigation
    // make array of letters in span tags
    $nav_arr = [];
    for ($i = 65; $i <= 90; $i++) {
    $nav_arr[chr($i)] = '<span>'.chr($i).'</span>';
    }

    // Go through content, if an item title begins with a letter, make it into a link instead of a span.
    $current_letter = '';
    perch_content_custom('Glossary', [
    'skip-template' => true,
    'raw' => true,
    'sort' => 'title',
    'sort-order' => 'ASC',
    'each' => function($item) {
    $word = strtoupper($item['title']);
    if (strcmp($word[0], $GLOBALS['current_letter']) !== 0) {
    $my_letter = $GLOBALS['current_letter'] = is_numeric($word[0]) ? '0-9' : $word[0];
    $GLOBALS['nav_arr'][$my_letter] = '<a href="#glossary-'.$my_letter.'">'.$my_letter.'</a>';
    }
    return $item;
    }
    ]);
    ?>
    <div class="glossary-nav">
    <?php
    // Display our alphabet
    foreach ($nav_arr as $key => $value) {
    echo $value;
    }
    ?>
    </div>
    <hr>
    <?php
    //reset $current_letter and display glossary, adding heading letters as required
    $current_letter = '';
    perch_content_custom('Glossary', [
    'template' => '_glossary_listing.html',
    'sort' => 'title',
    'sort-order' => 'ASC',
    'each' => function($item) {
    $word = strtoupper($item['title']);
    if (strcmp($word[0], $GLOBALS['current_letter']) !== 0) {
    $item['letter'] = $GLOBALS['current_letter'] = is_numeric($word[0]) ? '0-9' : $word[0];
    }
    return $item;
    }
    ]);
    ?>
    </div>
    </main>