YAFootnotes | stratos.me

YAFootnotes

This is a plugin, first inspired by Mr. Mike Nichols, is actually one to help authors use a more scientific way of publishing content with footnotes.

Description

Yet Another Footnotes (YAFootnotes) is a plugin that gives you the ability to add footnotes to any text you are writing. Writing a post with footnotes has never been easier and cleaner before. All you need to do is anchor a footnote at any point and then write it on the end of the paragraph or wherever it fits you.

Screenshots

Before parsing the text looks like this:

After parsing notice that footnotes have gone all the way to the bottom and a link has been placed at the text.

Requirements

No special requirement is needed. The plugin is tested with WordPress 2.6.X but i am pretty sure it will work with the future to come 2.7 and a few older ones. If you find any problems please leave a comment.

Installation

This plugin installs just like any other. Download it from here: YAFootnotes (1803) - 9.27 KB Then copy the yafootnotes.php file to your plugins directory and activate. Finally, start writing!

Usage

The usage of this plugin is fairly simple and is designed to keep your document as clean as possible. Below is an example of document the way you have to write it:

Lorem ipsum dolor sit amet, con sectetuer adipiscing elit, sed diam
tempor incidunt ut labore et dolore magna ali quarn erat volupat.{{1}}
venian, quis nostrud exerci tation ullamcorper{{2}} suscipit laboris
commodo consequat. Duis autem vel eum irure dolore

[[1]]This is the first footnote.[[1]]
[[2]]This is the second footnote.[[2]]

This is the next paragraph. Lorem ipsum dolor sit amet, con sectetuer
adipiscing elit, sed diam nonnumy nibh euismod tempor incidunt ut
labore et dolore magna ali quarn erat volupat. Ut wisi enim ad minim.

Notice the following:

  1. Just after “volupart” we wanted a footnote with the number of “1″ so we added it by adding: “{{1}}”. This is the way you anchor footnotes in the text.
  2. Now, for that footnote we need some text. We can place it anywhere we like. A common practice is at the end of the paragraph to summarize all the footnotes used in it. But, you can place then wherever you like, including the end of the post.
  3. To mark the text of the footnote we include it within double brackets and the footnote number. For instance, for the text of the first footnote we added “[[1]]This is the first footnote.[[1]]“. Please make sure you start and end with “[[FOOTNOTE_NUMBER]]” or else the parsing and outcome will be all messed up. Generally, the footnote body should be formatted like this: “[[FOOTNOTE_NUMBER]]footnote text[[FOOTNOTE_NUMBER]]“.

Easy and clean huh? This is what you will get after the plugin does it’s job.

Lorem ipsum dolor sit amet, con sectetuer adipiscing elit, sed diam
tempor incidunt ut labore et dolore magna ali quarn erat volupat.[1]
venian, quis nostrud exerci tation ullamcorper[2] suscipit laboris
commodo consequat. Duis autem vel eum irure dolore

This is the next paragraph. Lorem ipsum dolor sit amet, con sectetuer
adipiscing elit, sed diam nonnumy nibh euismod tempor incidunt ut
labore et dolore magna ali quarn erat volupat. Ut wisi enim ad minim.

FOOTNOTES
1. This is the first footnote.↑
2. This is the second footnote.↑

On the above example the ↑ will be links to the anchor within the text and the “[1]” and “[2]” will be links to the footnotes on the bottom.

Tweaks

There are a few things you can do to configure the output the way you like it.

Fixing the document anchors

I know that a more standard way of showing in a place that there is an anchor related to it is making the anchor number superscript. I chose that the default should be a bracketed number instead of superscript because it gets too tiny and readability might be affected. But if you want to change it there is a small change you can do on the code. Also, the default title to be displayed before the footnotes on the bottom, as you can see above, is “FOOTNOTES”. You can change that too. Please open yafootnotes.php with the editor of your liking and locate the following in line 14.

  1. $before_anchor = ‘[';//opening the anchor
  2. $after_anchor = ']‘;//closing the anchor
  3. $footnotes_title = ‘FOOTNOTES’;//the title to display before the footnotes on the bottom

Here is where you can define what will be placed before the anchor and after. It can be anything. From simple characters (like the brackets we have here) to HTML. To change this so it will show up as a superscript rather than a bracketed number make the following changes here:

  1. $before_anchor = ‘<sup>’;//opening the anchor
  2. $after_anchor = ‘</sup>’;//closing the anchor
  3. $footnotes_title = ‘FOOTNOTES’;//the title to display before the footnotes on the bottom

Notice that the “<sup>” tag is what makes the text be a superscript. Voila! You are done!

Adding some styling

There are two more things you can change to the way that the footnotes appear. The title “FOOTNOTES” that appears before the footnotes can be styled, besides changed as illustrated above. It is included within a span with the css class “yafootnote_head”. The footnotes’ body is included within a span with a class “yafootnote_body”. So, if you wanted to underline the title and make the bodies italic you should add the following to your theme’s CSS.

  1. span.yafootnote_head {
  2.     text-decoration: underline;
  3. }
  4. span.yafootnote_body {
  5.     font-style: italic;
  6. }

This is all you need to do.

Adding a space before the up arrow

Since, as Mike suggested, man footnotes end with a link it’s nice to seperate the last up arrow that is a link from the rest of the footnotes body. Here is how to do it. Look on line 38, somewhere at the end of the text that says:

  1. .$foot_text[1].‘">&amp; uarr;</a>’

and change it to:

  1. .$foot_text[1].‘">&amp; nbsp;&amp; uarr;</a>’

That will add a space after the body and before the link.

PS: For some reason the ampersant character comes up with it’s special HTML char (amp) but you get the idea i hope.



26 Responses to “ “YAFootnotes”

  1. [...] in the text itself. This is what the plugin does. I won’t get into more detail since the plugin’s page says it all (you can download it from there [...]

  2. Mike Nichols says:

    First, I want to thank Stratos for the good work he has done on this plugin. The plugin’s input mode is much more in keeping with the way that writers, scholars and scientists work.

    There is a further modification that can be made that Stratos sent to me via email. Most of my footnotes end with a URL, and the up-arrow for returning to the post body could be missed, since it is right at the end of the URL. This modification puts a space between the up-arrow and the end of the footnote and makes it much easier to find.

    In the yafootnotes.php code, look on line 38 for:
    .$foot_text[1].’”>↑‘

    Change this to:
    .$foot_text[1].’”> ↑‘

    Again, thanks to Stratos. He’s been a joy to work with!

  3. Mike Nichols says:

    Oops! The comment interpreted the characters to change as code! At least it shows you what it will look like! Let’s try this:

    The bit of code to look for on line 38 is “ampersand”uarr, where “ampersand” is the & figure. That’s the code for the up-arrow.

    Add to the front of this “ampersand”nbsp, where “ampersand” is the & figure. This is the code for the space figure.

  4. stratosg says:

    Thx for the nice words again Mike. I updated the page to reflect this tip too. Thanks again!

  5. baron says:

    hi. Thanks for plugin

    perfect.

    Regards

  6. [...] Writing a post with footnotes has never been easier and cleaner before. All you need to do is anchor a footnote at any point and then write it on the end of the paragraph or wherever it fits you. – Release page [...]

  7. [...] That was actually my part. This came after the successful co-operation between me and Mike for the YAFootnotes plugin. A few ideas have come up on the comments section but there were a couple that can actually [...]

  8. [...] dem WordPress Plugin YAFootnotes von stratosg von kann man jedem Text im Blog auf einfache Weise Fußnoten hinzufügen. [...]

  9. [...] other news, November was plugin month. I released two of them (YAFootnotes and “My Tag Cloud“) that were endorsed by the people and brought in quite a few [...]

  10. [...] the plugin’s name along with the word “exploit”. For instance, before using my YAFootnotes plugin, you can google “YAFootnotes exploit”. If there is something out there, chances [...]

  11. Stephanie says:

    Hello,

    I have had trouble using the “read more” tag together with YAFootnotes. If I insert the “read more” tag after the footnote tags in the body, then the footnotes before the “read more” tag repeat the body text.

  12. raapil says:

    Hi –

    I’ve been experimenting with the plugin and changed the code a bit, so I could have the plugin installed twice. Why? Because i thought the plugin could be used as a chapter- AND a footnote plugin. Look here:

    http://raapil.dk/?page_id=6464#foot_src_8

    Kapitel [8] = Chapter 8

    But the trouble is that the ‘footnote’, which should be a list at top of the post, is still being shown below as a footnote.

    I’m not coder, and I’m sure the changes I made in the php-file are strange, but something is working. How could we make it work perfectly?

    Here’s the php-file with the changes I made. I had to rename the file in order to install it, so I called it yachapters.php:

    <?php

    /*
    Plugin Name: YAchapters Plugin
    Plugin URI: http://www.stratos.me/wp-plugins/yafootnotes/
    Description: Yet Another Footnotes (YAFootnotes) is a plugin that gives you the ability to add footnotes to any text you are writing.
    Author: stratosg
    Version: 1.0
    Author URI: http://www.stratos.me
    */

    function yachapters($data){

    $before_anchor = ‘[';//opening the anchor
    $after_anchor = ']‘;//closing the anchor
    $footnotes_title = ‘Kapitler’;//the title to display before the footnotes on the bottom

    $foots = array();
    preg_match_all(“/\{\{[0-9]*\}\}/”, $data, $foots);//finding anchors in the text

    if(count($foots[0]) != 0){//there are footnotes to process!
    $foots_text = array();

    foreach($foots[0] as $foot){//finding the footnotes in the text
    $foot_num = trim($foot, ‘{}’);
    $foot_delim = ‘[['.$foot_num.']]’;
    $foot_start = strpos($data, $foot_delim) + strlen($foot_delim);
    $foot_end = strpos($data, $foot_delim, $foot_start);
    $foots_text[] = array(substr($data, $foot_start, $foot_end – $foot_start), $foot_num);
    $data = str_replace(‘{{‘.$foot_num.’}}’, ‘‘.$before_anchor.$foot_num.$after_anchor.’‘, $data);
    }

    $data = preg_replace(‘/\[\[[0-9]*\]\].*\[\[[0-9]*\]\]/’, ”, $data);

    $data .= ”.$footnotes_title.”;

    foreach($foots_text as $foot_text){
    $data .= ‘‘.$foot_text[1].’. ‘.$foot_text[0].’‘;
    }
    }

    return $data;
    }

    add_filter(‘the_content’, ‘yachapters’, 1, 1);

    ?>

  13. stratosg says:

    @Stephanie: I see where the problem is. I will try to fix it up and see what happens. In the meanwhile when you see the full text everything must be fine right?

    @Raapil: I will have to take a look at that. Although i think that the code has to be changed significantly to do that job. We shall see… I will let you know what happens…

  14. raapil says:

    Well, I found out that actually it doesn’t work as i thought. Even though I changed name and some code in the php WP only reads one of the two installed plugins (yafootnotes/yachapters).

    But in principle it should be the same function, just kind of reverse:

    Instead of bringing you from a place in the text to the bottom of the page, the yafootnote/chapter shall bring you from the top of the page to a place in the text – isn’t it almost the same, just reverse?

    Well, if you fix the code, you have made another WP-plugin :wink:

    Best, Lars

  15. raapil says:

    Hi again – It works with ordinary html code, but of course it’s a bit boring to work with / best Lars

  16. [...] a post with footnotes has never been easier and cleaner before… …..read more Download Plugin! Plugin Owner: stratosg Homepage: Visit Plugin’s Website Version 1.0 | [...]

  17. Stephanie says:

    Thank you for your help with the other item from February. The full text did appear fine otherwise.

    We’ve run into another issue. Law review articles often have multiple paragraphs in a footnotes (yeah, I know it is a bit excessive but I can’t change that!). However, multiple paragraphs in a footnote (between the footnote tags) causes the footnote text to also be in the body of the article. Is there anything I should be doing to prevent this?

    ———————-
    Example Wysiwyg Text:
    test {{1}}

    [[1]] This is a test.

    This is a test. [[1]]

    ———————-
    Example Output:
    test
    By Editor | August 24, 2009

    test [1]

    [[1]] This is a test.

    This is a test. [[1]]

    FOOTNOTES
    1. This is a test.

    This is a test. ↑

  18. [...] In: WordPress plugins 19 Nov 2009 My favorite footnotes plugin for wordpress. Go to Source [...]

  19. [...] 22nd, 2009 | Author: Maris SvirkstsWhile moving Darkmatter journal from WP-Footnotes plugin to YAFootnotes plugin (custom tweaked, moved because YAFootnotes was easier for writers/reviewers) we bumped into [...]

  20. Andreas says:

    Are there any news on the problem with the read-more tag? The problem still exists, unfortunately… Thanks! A

    • stratosg says:

      Hey there Andreas. No, no news there. Unfortunately i haven’t got around in updating this plugin for some time. I can’t guarantee i will but i can say i will try :) If i do i’ll post about it (because a couple of my plugins need an update anyways) so subscribe to get notified or keep coming back…

  21. Thank you for this plugin!

    After inspecting all the other “footnotes” plugins available for wordpress, we decided yours is the best.
    We are now using it on our website with some modifications to suit our needs; e.g. multiple references to the same book, highlighting.

    Again, thank you and keep up the good work!

    Joseph W. of UrologyJournal.us

  22. David Kane says:

    Hi Stratosg,

    I have modified your code a bit:

    ————-
    <?php

    /*
    Plugin Name: YAFootnotes Plugin
    Plugin URI: http://www.stratos.me/wp-plugins/yafootnotes/
    Description: Yet Another Footnotes (YAFootnotes) is a plugin that gives you the ability to add footnotes to any text you are writing.
    Author: stratosg
    Version: 1.1
    Author URI: http://www.stratos.me
    */

    function yafootnotes($data){
    $debug = true;
    $before_anchor = '[';//opening the anchor
    $after_anchor = ']';//closing the anchor
    $footnotes_title = 'FOOTNOTES';//the title to display before the footnotes on the bottom
    $foots = array();
    preg_match_all("/\{\{([0-9]*):([^}]*)\}\}/", $data, $foots);//finding anchors in the text
    $data .= '’.print_r($foots).”;
    if(count($foots[0]) != 0){//there are footnotes to process!
    $count = 0;
    foreach($foots[1] as $foot){//finding the footnotes in the text
    $data = str_replace(‘{{‘.$foots[1][$count].’:’.$foots[2][$count].’}}’, ‘‘.$before_anchor.$foots[1][$count].$after_anchor.’‘, $data);
    //$data .= ‘xx’.$foot[$count].’:’.$foots[2][$count].’xx‘;

    $count += 1;
    }
    //$data .= ‘yy’.print_r($foots).’yy’;
    $data .= ”.$footnotes_title.”;
    $count = 0;
    foreach($foots[2] as $foot_text){
    $data .= ‘‘.$foots[1][$count].’. ‘.$foot_text.’‘;
    $count += 1;
    }

    }
    return $data;
    }
    add_filter(‘the_content’, ‘yafootnotes’, 1, 1);
    ###
    # usage {{1:footnotetext}} blah blah {{2:footnote other text}} etc.
    #
    ?>

  23. David Kane says:

    Instead of writing
    {{1}}[[1]]footnote text[[1]]
    I now can write
    {{1:footnote text}}
    Maybe there are problems with this that you can forsee. The main innovation is the use of backreferences in the preg_match_all() function, which makes the code a bit shorter.

    David Kane,
    Waterford Institute of Technology Libraries

Leave a Reply