mitcho Michael 芳貴 Erlewine

Postdoctoral fellow, McGill Linguistics.

blog

Posts Tagged ‘YARPP’

Matt Mullenweg recommends YARPP on Tekzilla!

Sunday, June 14th, 2009

A new user of my WordPress plugin tipped me off to a recent Tekzilla segment where WordPress founder [[Matt Mullenweg]] recommended Yet Another Related Posts Plugin as one of his personal favorite WordPress plugins. Thanks Matt! ^^

Fixing Geshi on line 2132

Saturday, June 13th, 2009

I recently noticed that some of my blog posts, most notably my Templates in YARPP 3 article, was producing a PHP error:

Warning: preg_match() [function.preg-match]: Compilation failed: unrecognized character after (?< at offset 3 in /…/html/blog/wp-content/plugins/wp-syntax/geshi/geshi.php on line 2132

This seemed to be coming from the version 1.0.8.4 version of Geshi I had installed. A quick google search for “geshi line 2132” gives you over a thousand errors, so this seems to be common issue. Geshi is a fabulous and popular syntax highlighter and is the core component of the WP-Syntax plugin for WordPress.

I did some digging around and realized that the issue was with the compilation of this monstrosity of a regular expression, used (as far as I can tell) to identify PHP code snippets, for example the <?php … ?> keywords:

/(?<start><\\?(?>php\b)?)(?:
(?>[^\"'?\\/<]+)|
\\?(?!>)|
(?>'(?>[^'\\\\]|\\\\'|\\\\\\\|\\\\)*')|
(?>\"(?>[^\"\\\\]|\\\\\"|\\\\\\\\|\\\\)*\")|
(?>\\/\\*(?>[^\\*]|(?!\\*\\/)\\*)*\\*\\/)|
\\/\\/(?>.*?$)|
\\/(?=[^*\\/])|
<(?!<<)|
<<<(?<phpdoc>\w+)\s.*?\s\k<phpdoc>
)*(?<end>\\?>|\Z)/sm

Not knowing exactly where to start in diagnosing this crazy expression, I simply disabled those “script delimiters” in the geshi/php.php file. The sections I commented out are lines 1080-1101. Now the script delimiters like &lt;?php don’t get highlighted nicely, but I feel that’s a small price to pay for eliminating these errors. Another solution for the WP-Syntax users seems to be to downgrade to 0.9.4. Hopefully in the near future an update to Geshi will come out which fixes this issue once and for all.

Using Templates with YARPP 3

Wednesday, January 14th, 2009

I am no longer maintaining the information here. It is out of date. Please see the Developing with YARPP section of the YARPP readme.

If you have a YARPP support question not directly related to the templating feature, please use the YARPP support forums.

Version 3 of Yet Another Related Posts Plugin is a major rewrite which adds two new powerful features: caching and templating. Today I’m going to show you how you can use templates to customize the look of your related posts output.1

Previously with YARPP you were relatively limited in the ways you could present related posts. You were able to set some HTML tags to wrap your posts in and choose how much of an excerpt (if any) to display. This limited interface worked great for many users—indeed, these options still exists in YARPP 3.0. However, there’s also a new option for those of you who want to put your PHP skills to work and have complete control over your related posts display. The option will let you choose any files in the templates subdirectory of YARPP.

templates interface

(more…)


  1. For those of you interested in the WP and SQL voodoo used to make this happen, I’ve posted a more technical article

This is what a release looks like

Wednesday, December 10th, 2008

This is what the latest release (2.1.6) of my Yet Another Related Posts Plugin looked like under Mint, using my WordPress plugin downloads pepper, which in turn gets its data from wordpress.org:

It’s always interesting to see these release spikes in download traffic. Note that this release was on the Wednesday but that was during the day, so Wednesday’s traffic is still higher than the normal ~300/day level, while the big peak (by day) is on Thursday. Too bad wordpress.org doesn’t give me hourly stats, though I guess that would be a little ridiculous.

YARPP is just about at that 35k download mark. I’m looking forward to the next release. ^^

External orders in WordPress queries

Saturday, November 29th, 2008

The advanced WordPress user is intimately familiar with query_posts, the function which controls which posts are displayed in “The Loop.” query_posts gives plugin and theme writers the ability to display only posts written in Janary (query_posts("monthnum=1")) or disallow posts from a certain category (query_posts("cat=-529")1). One of the parameters you can set here is orderby which affects the ordering of the posts returned, with allowed values such as author, date, or title. But what if you want to order your posts in some other order, defined outside of your wp_posts table? Here I’m going to lay out some thoughts on rolling your own external ordering source for WordPress queries.

In order to introduce an external ordering source, we need to do four things: 1. create the external ordering source, 2. hook up (read “join”) the external ordering source 3. make sure we use that order, and 4. make it play nice. ^^

By the way, I’m going to assume you, dear reader, are PHP-savvy, proficient in MySQL, and already know a little about WordPress. This how-to is not for the PHPhobic.

(more…)


  1. This, incidentally, is precisely what I do to hide, by default, my tweets in my index.php and archives.php

Keep up with Yet Another Related Posts Plugin with RSS!

Saturday, October 4th, 2008

As more and more people have been using my Yet Another Related Posts Plugin for [[WordPress]], I thought it would be nice to have an RSS feed for users to stay on top of the latest releases.

Clicking on a version’s permalink will let you download the plugin. Subscribe now and be the first to find out when the upcoming version 2.1 is released!

I decided to semi-automate this RSS-producing process as well. As a plugin developer using wordpress.org’s plugin hosting, I sync a local copy of the plugin to their server using [[SVN]]. I wrote a [[PHP]] script to get the modification date information directly from the local files, parse the version log in the read me, and produce the RSS feed. If there’s an interest, perhaps I’ll release this code in the future.

Yet Another Related Posts Plugin

Saturday, December 29th, 2007

UPDATE:

This posting is now outdated… for the latest information on YARPP, please visit YARPP’s very own page on my site, or its page on wordpress.org. If you have questions, please submit on the wordpress.org forum. Thanks!

Description

Today I’m releasing Yet Another Related Posts Plugin (YARPP1) 1.0 for WordPress. It’s the result of some tinkering with Peter Bowyer’s version of Alexander Malov & Mike Lu’s Related Entries plugin. Modifications made include:

  1. Limiting by a threshold: Peter Bowyer did the great work of making the algorithm use [[mysql]]’s fulltext search score to identify related posts. But it currently just displayed, for example, the top 5 most “relevant” entries, even if some of them weren’t at all similar. Now you can set a threshold limit2 for relevance, and you get more related posts if there are more related posts and less if there are less. Ha!
  2. Being a better plugin citizen: now it doesn’t require the user to click some sketchy button to alter the database and enable a fulltext key. Using register_activation_hook, it does it automagically on plugin activation. Just install and go!
  3. Miscellany: a nicer options screen, displaying the fulltext match score on output for admins, an option to allow related posts from the future, a couple bug fixes, etc.

Installation

Just put it in your /wp-content/plugins/ directory, activate, and then drop the related_posts function in your WP loop. Change any options in the Related Posts (YARPP) Options pane in Admin > Plugins.

You can override any options in an individual instance of related_posts using the following syntax:

`related_posts(limit, threshold, before title, after title, show excerpt, len, before excerpt, after excerpt, show pass posts, past only, show score);

Most of these should be self-explanatory. They’re also in the same order as the options on the YARPP Options pane.

Example: related_posts(10, null, 'title: ') changes the maximum related posts number to 10, keeps the default threshold from the Options pane, and adds title: to the beginning of every title.

There’s also a related_posts_exist) function. It has three optional arguments to override the defaults: a threshold, the past only boolean, and the show password-protected posts boolean.

Examples

For a barebones setup, just drop <?php related_posts(); ?> right after <?php the_content() ?>.

On my own blog I use the following code with <li> and </li> as the before/after entry options:

<?php if (related_posts_exist()): ?>
<p>Related posts:
<ol>
<?php related_posts(); ?>
</ol>
</p>
<?php else: ?>
<p>No related posts.</p>
<?php endif; ?>

Coming soon (probably)

  1. Incorporation of tags and categories in the algorithm. I’ve gotten the code working, but I still need to think about what the most natural algorithm would be for weighing these factors against the mysql fulltext score currently used (and works pretty well, I must say).
  2. Um, something else! Let me know if you have any suggestions for improvement. ^^

Version log

1.0 Initial upload (20071229)

1.0.1 Bugfix: 1.0 assumed you had Markdown installed (20070105)


  1. Pronounced “yarp!”, kind of like this, but maybe with a little more joy:
     

  2. Did you know that threshold has only two h’s!? I’m incensed and just went through and replaced all the instances of threshhold in my code. It’s really not a thresh-hold!?