Skip to content

Instantly share code, notes, and snippets.

@ibolmo
Created October 24, 2012 20:09
Show Gist options
  • Select an option

  • Save ibolmo/3948524 to your computer and use it in GitHub Desktop.

Select an option

Save ibolmo/3948524 to your computer and use it in GitHub Desktop.
footnote helper
<?php footnote(1) ?>
1st footnote
<?php end_footnote() ?>
<?php footnote(2) ?>
2nd footnote
<?php end_footnote() ?>
<?php footnote(2) ?>
2nd footnote
<?php end_footnote() ?>
<?php footnote(1) ?>
1st footnote
<?php end_footnote() ?>
<?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)));
}
<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