|By Shamus||May 24, 2006||Programming||19 comments|
This is a wordpress plugin I’ve made that will find certain words – which you define – and turn them into links which lead to your dictionary. The user can mouse over the word to see a short definition, or they can follow the link to see the full definition. This is handy if you have a lot of jargon on your blog which might confuse newcomers.
According to Steven Sempai, the TV series of Read or Die differs greatly from the OVA. Meganekko agent paper is only in the OVA, and contrary to common practice, the OVA has less fan service than the TV series. There is no ecchi, and most otaku will be glad to hear there isn’t a lolicon character, either. The cast is mostly female, but this isn’t a harem comedy. Agent paper is a sort of quasi-mahou shojou who can manipulate paper to form weapons and tools. There aren’t any mecha, and while agent paper is sometimes kawaii you won’t find any slapstick chibi humor here. The Seiyuu in the series are all excellent. I thought the story was silly, but some people liked it. If you did, then akanbe!!
In the above text, I didn’t create any of the tooltops or hyperlinks, I just typed the words and the plugin handled the rest. If I edit the post, I don’t have to deal with the dense clutter required to make all of that work. Editing that paragraph in HTML would be a nightmare, but with the plugin I just edit the plain text and the links happen as if by magic.
Note that this plugin requires PHP5. If your webserver does not have this, the plugin won’t work!
First, download the plugin here. Unzip the files. You’ll need to edit lexicon.php (just a bit!) and then make your dictionary.
This plugin isn’t very advanced, and requires a little more setup than most plugins to get it working right. Deep breath, you can do it.
- Create the dictionary
The first step is to create the dictionary file you will use, which is called dictionary.txt by default. You can see my dictionary here. There is an example dictionary included in the zip as well.
For each word in your dictionary, there are 4 lines, the last of which is optional. Line 1 is the word (or even phrase) itself. Line 2 is a short definition that will be used as a tooltip. Line 3 is the full definition. Line 4 is optional, and can specify an image to use for the dictionary entry. Then you must have at least one blank line, and then the process starts over with line 1 of the next word, until the end of the file is reached. If you omit the last line (the image) then the entry just won’t have one. No biggie.
For each entry in the dictionarty there are several lines:
- Line 1 is the word itself.
- Line 2 is the short definition used as a tooltip when the mouse hovers over the word
- Line 3 is the full definition. Remember, it all has to be on one line!
- Line 4 is the “see also”. Just put words seperated by commas and the dictionary will use them to cross-reference. Leave a BLANK LINE if you don’t want this.
- Line 5 is the image, including path. Leave a BLANK LINE if you don’t want an image
- Leave one more BLANK LINE before you list the next entry.
Note that you don’t need to sort the entries. The plugin will sort them into alphabetical order for you.
Note that if the word in your dictionary is defined in ALL CAPS, then it is treated as an acronym, and it will only turn into a link if it is written in all caps. If you do not define the word in all uppercase, it will be treated normally and any case combination of that word will become a dictionary link.
Make a new post. In this post add the following text:
That is a colon, the word “LEXICON” in all caps, and then another colon. The plugin will replace this word with the contents of your entire dictionary, complete with links and images. You can see mine here.
Now edit the lexicon.php. If you don’t know PHP this might be a little scary. Be brave. Just a few lines down you’ll see:
$ad_dictionary_url = "www.example.net/somepage";
This is where you tell the plugin how to find your dictionary. Inside of the quotes, put the address of the entry you just created. If the permalink to that post is www.myblog.com/wordpress/my-dictionary/ then change the line to say:
$ad_dictionary_url = "www.myblog.com/wordpress/my-dictionary/";
All done! Any of the words that appear in your dictionary will become links. You can add or change the contents of the dictionary at any time.
Dictionary words which appear inside of HTML tags are ignored. Words appearing after a < and before a < are assumed to be an HTML tag and the plugin won’t mess with them.
If you do NOT want a word to become a dictionary link, preceed the word with a percent symbol. For example:
Note that you should do this if the word appears within a link! If you don’t, the plugin will still turn the word into a dictionary link, which will break the link you were trying to create and make a mess of the HTML.