Created
October 24, 2012 20:09
-
-
Save ibolmo/3948524 to your computer and use it in GitHub Desktop.
footnote helper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php footnote(1) ?> | |
| 1st footnote | |
| <?php end_footnote() ?> | |
| <?php footnote(2) ?> | |
| 2nd footnote | |
| <?php end_footnote() ?> | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php footnote(2) ?> | |
| 2nd footnote | |
| <?php end_footnote() ?> | |
| <?php footnote(1) ?> | |
| 1st footnote | |
| <?php end_footnote() ?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| use_helper('Tag'); | |
| $footnotes = array(); | |
| $footnote_ptr = 0; | |
| function footnote($reference) | |
| { | |
| global $footnote_ptr; | |
| $footnote_ptr = $reference; | |
| ob_start(); | |
| } | |
| function end_footnote() | |
| { | |
| global $footnotes; | |
| global $footnote_ptr; | |
| $footnotes[$footnote_ptr] = ob_get_clean(); | |
| } | |
| function get_footnotes() | |
| { | |
| global $footnotes; | |
| ksort($footnotes); | |
| return $footnotes; | |
| } | |
| function link_to_footnote($reference, $options = array()) | |
| { | |
| return content_tag('sup', content_tag('a', $reference, array_merge(array('href' => "#footnote_$reference"), $options))); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <dl class="footnotes"> | |
| <?php foreach (get_footnotes() as $i => $note): ?> | |
| <dt id="footnote-<?= $i ?>"><?= ($i + 1) ?>:</dt> | |
| <dd><?= $note ?></dd> | |
| <?php endforeach ?> | |
| </dl> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment