This is a little technical post for anyone who is interested in using the Ajaxified Expand Post NOW plug-in[1] and Rob Miller’s Footnotes plug-in[2] together. On this website, I’m running AEPN version 0.7 beta 7, Footnotes version 1.2.1, and WordPressμ version 2.8.2, which are the latest versions as of this writing.
The AEPN plug-in truncates a post and appends an “[Expand post]” button, whenever it is displayed other than on a single page by itself. Clicking on the button fetches and displays the rest of the post. The Footnotes plug-in should be self-explanatory.
The problem with using these two plug-ins together is that if any citations are made before the fold (i.e., the <!--more--> tag), the corresponding footnotes will appear at the bottom of the (collapsed) post. When the post is subsequently expanded, those footnotes will appear again at the end of the expansion, so that they are displayed twice.
The fix for this is rather simple. In the “footnotes.php” file, surround the final if-else block with a test to see if a single post is being displayed. If so, execute the block as before. Otherwise, return the post’s content without the accompanying footer. The code should look like this:
if( is_single() ) { if ( strpos($content, '<references />') === false ) return $content . $footer; else return str_replace('<references />', $footer, $content); } else { return $content; }
When the AEPN plug-in fetches a post to expand it, it is treated as a single post, and so the footnotes will show up correctly — once, at the bottom of the expansion.
In the “ajaxified-expand-post-now.php” file, add the following lines to the top of the “getPost” function:
global $post; $post->ID = $id;
This is needed so that the names for the footnote anchors in the expanded portion of the post are generated correctly. Citations made before the fold will link to the post’s single page, whereas citations made after it[3] will link to the footnotes section at the bottom of the expansion, on the current page.
Finally, it may be necessary to use a so-called “kses hack” to prevent the “ref” and “references” tags needed by the Footnotes plug-in from being stripped by WordPressμ. How to do this is beyond the scope of this post.
See also this previous post for an example of how the Footnotes plug-in can be used with the Wikindx bibliographical management system to create a bibliographical citation.
– davinci
Notes
- ↑1 Ajaxified Expand Post NOW plug-in website: http://blog.chweng.idv.tw/wordpress/ajaxified-expand-post-now
- ↑2 Rob Miller’s Footnotes plug-in website: http://robm.me.uk/projects/plugins/wordpress/footnotes
- ↑3 Such as this one.












Apparently, the UTW plug-in has the same problem.
Slightly OT, questions from a newbie regarding the AEPNW plugin–How were you able to take out the collapse link from the top? I had the bottomlink activated, but the collapse link would be displayed twice. Also, I’d like to know how you added the graphic on the loaded scene.
I’ll answer the second question first. To display a graphic while loading data, just put an HTML “img” tag in your loading message by setting the “aepnLoadingMsg” variable.
I don’t know what you’re talking about when you refer to the “collapse link from the top”. Can you post a link to a web site that shows this? I think you’re asking how to customise the “expand”/”collapse” messages, and the answer is that you can do this easily by editing the plugin’s source file, if you know PHP.
– davinci
I got the first one when I was messing around with the source. As for the collapse link from top that I want removed, it’s from a theme that I’m making. Say I have “hello this is a post”. The plugin works fine but has the collapse (”less” by default) link on top/before “this is a post” whereas I want it below/after the body, like how yours behaves. I thought setting the bottomlink to true would do that but instead of transferring the position, it adds another link at the after/at the bottom.
You’ll have to excuse my php as I’m not really good with it. I’m still messing around but I’m assuming I need to edit these lines to remove the top/default instance of collapse?
[quote]
if (!$more) {
$content=preg_replace(’/(.*)/’, ($postLinkPrefix.’‘.$postMore.’‘.$postLess.’‘.$postLinkPostfix), $content);
$content.=”;
[/quote]
oops. That looked different. Post got messed, due to the links, duh, my bad. Anyway, I was pertaining to lines 62-64 of the plugin, but I’m not sure, and how to go about it if ever.
The only places where the collapse link appears is where
$postLessis referenced in the source code, so it shouldn’t be that hard to find and edit it to make it do what you want. I don’t remember ever having a collapse link at the top of the post, but I probably customised the code when I downloaded it. Do you understand regular expressions at all, and what “preg_replace” is doing?– davinci
From what I understand, prereg replaces the first parameter with the second. I knew I had to edit where $postLess appeared (thrice, the first one was the setting a prefix/postfix, second was if bottom placement was enabled, and third was with the preg_replace, so it had to be the third, which is lines 62-66). If $content is not equal to more, then search the content for the more link and replace it with the less link. Then add the div viewbox-p before throwing back the content.
At first I thought all I needed to do was remove this prereg in order to take out the replacement and return content untouched (bottom link would still appear since it was added in another function), but doing so killed the script, and more link no longer expanded. I tried taking out just the postLess link in the prereg, and also replacing the second value to ‘ ‘ so that the top more link would disappear, but I would get an “error connecting to server, please try again later” when clicking on the more link.
I’m continually trying to tinker with those lines, but with no success so far. Again, I apologize for my ignorance as I’m not well versed with php.
I think I understand what you’re asking. You want the “collapse/expand” link to appear after the newly loaded content, instead of where the “more” tag used to be. The way to do that is to put the “viewBox-p” div right after the
$postMorelink, instead of right after the$postLessone.You should replace the TWO lines inside the “if” block with something like this:
I hope that helps.
– davinci
That did it. Thanks a lot! For the others who want the same result, type it manually, copy pasting doesn’t seem to work, I didn’t check if there were differences.
Interesting site. I might also try out rob miller’s footnotes plugin, which I discovered in this post. Double Thanks! Will definitely check your site every now and then. Oh, and Happy New Year.
You’re welcome. Happy New Year to you too.
– davinci