84
mitcho @ WordCamp Birmingham, January 2012 RELATE ALL THE THINGS! YARPP!

Relate all the things!

Embed Size (px)

DESCRIPTION

So your new site’s launched: great content, beautiful design, and SEO’ed like whoah. But when a visitor comes in for one particular page, how do you encourage them to engage further with your content rather than leave? The Yet Another Related Posts Plugin for WordPress—aka YARPP—was built exactly out of this concern. YARPP offers your visitors a number of “related posts” which may also interest them. These “related posts” are chosen automatically by a unique algorithm which compares the current post or page with other content on the site.Advocated by the likes of Matt Mullenweg (WordPress) and Matt Cutts (Google), YARPP is by far the most popular content recomendation plugin for WordPress. Learn about the past and future of YARPP straight from its author, mitcho. I’ll talk about YARPP’s internals, share some advanced tips for using and customizing YARPP, and will debut YARPP’s custom post type support.

Citation preview

Page 1: Relate all the things!

mitcho @ WordCamp Birmingham, January 2012RELATE ALL THE THINGS!

YARPP!

Page 2: Relate all the things!

mitcho (Michael 芳貴 Erlewine)

http://mitcho.com, @themitcho, @yarpp

Page 3: Relate all the things!

toothpastefordinner.com

The solution: suggesting related content

Page 4: Relate all the things!

Yet Another Related Posts Plugin

Page 5: Relate all the things!

Yet Another Related Posts Plugin

Page 6: Relate all the things!

One of my favorite [plugins] I just activated on my blog is called Yet Another Related Posts Plugin...

I've been blogging seven or eight years now so I have a lot of archives, and it actually surprises me sometimes when I blog about something and I visit the permalink to see I've written about it before... and it also increases the traffic on your blog because when they come in just to one entry, they'll see this other stuff going on.

Matt Mullenweg

Page 7: Relate all the things!
Page 8: Relate all the things!

TODAY

Page 9: Relate all the things!

1. How does YARPP work?

TODAY

Page 10: Relate all the things!

1. How does YARPP work?2. Relate all the things!

TODAY

Page 11: Relate all the things!

1. How does YARPP work?2. Relate all the things!3. No, really—how does YARPP work?

TODAY

Page 12: Relate all the things!

1. How does YARPP work?2. Relate all the things!3. No, really—how does YARPP work?

TODAY

Page 13: Relate all the things!

How YARPP works

Page 14: Relate all the things!

What’s “related”?CC-BY-NC-ND http://www.flickr.com/photos/twcollins/109069524/

Page 15: Relate all the things!

My trip to Greece

My thoughts on Google+

20 ways to use Path now

I love my iPhone!

Fluid dynamics in 10 min

10 Great Eats in Birmingham

Writing your own WordPress plugin

Nikon D90 review

Living off the grid

“THE POOL”

Taiwan travel tipsVISITORreference entry:

Page 16: Relate all the things!

The criteria:

• Title keywords*

• Content body keywords*

• Tags

• Categories

* a value computed by a MySQL FULLTEXT MATCH of the reference

entries’ top 20 keywords against the pool entries’ full values

2.73.2

1

2

SCORES:

Page 17: Relate all the things!

The “match score”:

1310

WEIGHTS:

Page 18: Relate all the things!

The “match score”:A weighted sum of the criteria:

1310

WEIGHTS:

Page 19: Relate all the things!

The “match score”:A weighted sum of the criteria:

2.7 × 1 + 2.8 × 3 + 1 x 1 + 2 x 0 = 12.1

1310

WEIGHTS:

Page 20: Relate all the things!

The “match score”:A weighted sum of the criteria:

2.7 × 1 + 2.8 × 3 + 1 x 1 + 2 x 0 = 12.1

12.1 > 7 (“match threshold”) so related!

1310

WEIGHTS:

Page 21: Relate all the things!

The result:

Page 22: Relate all the things!

The result:

• A good, organic sense of “relatedness”

Page 23: Relate all the things!

The result:

• A good, organic sense of “relatedness”• Default settings are pretty good :)

Page 24: Relate all the things!

The result:

• A good, organic sense of “relatedness”• Default settings are pretty good :)• Sometimes results in less than the

specified number of results

Page 25: Relate all the things!

The result:

• A good, organic sense of “relatedness”• Default settings are pretty good :)• Sometimes results in less than the

specified number of results• A feature, not a bug

Page 26: Relate all the things!

The result:

• A good, organic sense of “relatedness”• Default settings are pretty good :)• Sometimes results in less than the

specified number of results• A feature, not a bug

• Not symmetric, not transitive

Page 27: Relate all the things!

Templates:Uber-customize the related posts display

http://phillprice.com http://elliottgoodman.com

Page 28: Relate all the things!

Templates:<?php if (have_posts()): ?><h3>Related Photos</h3><ol> <?php while (have_posts()) : the_post(); ?> <?php if (has_post_thumbnail()):?> <li><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"> <?php the_post_thumbnail(); ?></a></li> <?php endif; ?> <?php endwhile; ?></ol><?php endif; ?>

http://mitcho.com/blog/projects/yarpp-3-templates/

Page 29: Relate all the things!

1. How does YARPP work?2. Relate all the things!3. No, really—how does YARPP work?

TODAY

Page 30: Relate all the things!

RELATE ALL THE THINGS!

YARPP!

Page 31: Relate all the things!

RELATE ALL THE THINGS!

YARPP!

custom queries and CPT support

Page 32: Relate all the things!

Custom queries

Page 33: Relate all the things!

Custom queries

• YARPP has always had posts and pages

Page 34: Relate all the things!

Custom queries

• YARPP has always had posts and pages• Options set in one place

Page 35: Relate all the things!

Custom queries

• YARPP has always had posts and pages• Options set in one place• No way to programmatically override

Page 36: Relate all the things!

Custom queries

• YARPP has always had posts and pages• Options set in one place• No way to programmatically override

• YARPP 3.5 allows one-off custom displays

Page 37: Relate all the things!

Custom queries

related_posts();

Page 38: Relate all the things!

related_posts(array(), $ID, true); *

* Some YARPP function signatures are changed in YARPP 3.5 to

make them all uniform. Sorry to break it to you. (Ha!)

Custom queries

Page 39: Relate all the things!

related_posts(array());

Custom queries

Page 40: Relate all the things!

related_posts(array());

THE FUN PART

Custom queries

Page 41: Relate all the things!

related_posts(array( 'order' => 'post_title ASC'));

Custom queries

Page 42: Relate all the things!

related_posts(array( 'order' => 'post_title ASC'));

Custom queries

a wp_posts column and ASC or DESC

Page 43: Relate all the things!

Custom queries

related_posts(array( 'template' => 'yarpp-template.php'));

Page 44: Relate all the things!

Custom queries

related_posts(array( 'template' => 'yarpp-template.php'));

a file in your active theme

Page 45: Relate all the things!

Custom queries

related_posts(array( 'weight' => array( 'body' => 1, 'title' => 3 ), 'threshold' => 5));

Page 46: Relate all the things!

related_posts(array( 'weight' => array( 'body' => 1, 'title' => 3, 'tax' => array( 'post_tag' => 1 ) )));

Custom queries

Page 47: Relate all the things!

Custom queries

related_posts(array( 'weight' => array( 'body' => 1, 'title' => 3, 'tax' => array( 'post_tag' => 1, 'category' => 2 ) )));

Page 48: Relate all the things!

Custom queries

related_posts(array( 'weight' => array( 'body' => 1, 'title' => 3, 'tax' => array( 'post_tag' => 1, 'category' => 2 ) ))); your taxonomy here

Page 49: Relate all the things!

related_posts(array( 'weight' => array(...), 'require_tax' => array( 'post_tag' => 1 )));

Custom queries

Page 50: Relate all the things!

related_posts(array( 'weight' => array(...), 'require_tax' => array( 'post_tag' => 1 )));

Custom queries

taxonomy # requiredin common

Page 51: Relate all the things!

Custom queries

related_posts(array( 'recent' => '3 month'));

Page 52: Relate all the things!

related_posts(array( 'exclude' => array(32,12,84)));

Custom queries

Page 53: Relate all the things!

related_posts(array( 'exclude' => array(32,12,84)));

Custom queries

term_taxonomy_ids

Page 54: Relate all the things!

Relate all the things!YARPP 3.5 adds Custom Post Type support

yarpp_related(array( 'post_type' => array('people','animals')));

Page 55: Relate all the things!

YARPP!

Page 56: Relate all the things!

POP QUIZ!YARPP!

Page 57: Relate all the things!

yarpp_related(array( 'post_type' => array('movies'), 'weight' => array( 'title' => 1, 'tax' => array( 'actor' => 1 ) )));

Page 58: Relate all the things!

yarpp_related(array( 'post_type' => array('movies'), 'weight' => array( 'title' => 1, 'tax' => array( 'actor' => 1 ) )));

related movies considering titles and actors

Page 59: Relate all the things!

yarpp_related(array( 'post_type' => array('book'), 'recent' => '1 year', 'weight' => array( 'title' => 1, 'tax' => array( 'author' => 1 ) )));

Page 60: Relate all the things!

yarpp_related(array( 'post_type' => array('book'), 'recent' => '1 year', 'weight' => array( 'title' => 1, 'tax' => array( 'author' => 1 ) )));

related books considering titles and authors and published in the past year

Page 61: Relate all the things!

yarpp_related(array( 'post_type' => array('toy'), 'require_tax' => array( 'age_range' => 1 )));

Page 62: Relate all the things!

yarpp_related(array( 'post_type' => array('toy'), 'require_tax' => array( 'age_range' => 1 )));

related toys with at least one age range in common

Page 63: Relate all the things!

As you like it

Page 64: Relate all the things!

As you like it

• yarpp_related_exist() returns boolean

Page 65: Relate all the things!

As you like it

• yarpp_related_exist() returns boolean• yarpp_get_related() returns array of

objects

Page 66: Relate all the things!

As you like it

• yarpp_related_exist() returns boolean• yarpp_get_related() returns array of

objects• just like WP’s get_posts()

Page 67: Relate all the things!

Caveat:

• Custom queries with related_posts() or yarpp_related() aren’t cached in YARPP’s

internal cache

• If you use them a lot, cache the results yourself (which is another talk...)

Page 68: Relate all the things!

1. How does YARPP work?2. Relate all the things!3. No, really—how does YARPP work?

TODAY

Page 69: Relate all the things!

Do the mathSELECT 4024 as reference_ID, ID,

ROUND(0 + (MATCH (post_content) AGAINST ('carved panorama great ones lantern including chomsky photos richards share flickr jack norvin stata pumpkins couple team firefox halloween ')) * 1 + (MATCH (post_title) AGAINST ('halloween happy ')) * 1 + count(distinct if( terms.term_taxonomy_id in (598,447), terms.term_taxonomy_id, null )) * 1 + count(distinct if( terms.term_taxonomy_id in (649,47,808,861,824), terms.term_taxonomy_id, null )) * 1,1) as score

from wp_posts left join wp_term_relationships as terms on ( terms.object_id = wp_posts.ID )

where post_status in ( 'publish', 'static' ) andID != '4024' andpost_date <= '2010-10-29 16:22:51' andpost_password ='' andpost_type = 'post'

group by ID having score >= 5.00 and

bit_or(terms.term_taxonomy_id in (601)) = 0order by score desc limit 5

Page 70: Relate all the things!

Do the mathSELECT 4024 as reference_ID, ID,

ROUND(0 + (MATCH (post_content) AGAINST ('carved panorama great ones lantern including chomsky photos richards share flickr jack norvin stata pumpkins couple team firefox halloween ')) * 1 + (MATCH (post_title) AGAINST ('halloween happy ')) * 1 + count(distinct if( terms.term_taxonomy_id in (598,447), terms.term_taxonomy_id, null )) * 1 + count(distinct if( terms.term_taxonomy_id in (649,47,808,861,824), terms.term_taxonomy_id, null )) * 1,1) as score

from wp_posts left join wp_term_relationships as terms on ( terms.object_id = wp_posts.ID )

where post_status in ( 'publish', 'static' ) andID != '4024' andpost_date <= '2010-10-29 16:22:51' andpost_password ='' andpost_type = 'post'

group by ID having score >= 5.00 and

bit_or(terms.term_taxonomy_id in (601)) = 0order by score desc limit 5

the score formula

Page 71: Relate all the things!

Do the mathSELECT 4024 as reference_ID, ID,

ROUND(0 + (MATCH (post_content) AGAINST ('carved panorama great ones lantern including chomsky photos richards share flickr jack norvin stata pumpkins couple team firefox halloween ')) * 1 + (MATCH (post_title) AGAINST ('halloween happy ')) * 1 + count(distinct if( terms.term_taxonomy_id in (598,447), terms.term_taxonomy_id, null )) * 1 + count(distinct if( terms.term_taxonomy_id in (649,47,808,861,824), terms.term_taxonomy_id, null )) * 1,1) as score

from wp_posts left join wp_term_relationships as terms on ( terms.object_id = wp_posts.ID )

where post_status in ( 'publish', 'static' ) andID != '4024' andpost_date <= '2010-10-29 16:22:51' andpost_password ='' andpost_type = 'post'

group by ID having score >= 5.00 and

bit_or(terms.term_taxonomy_id in (601)) = 0order by score desc limit 5

table join

in YARPP 3.5, just two tables!

Page 72: Relate all the things!

I got cache. Mega cache.

Page 73: Relate all the things!

I got cache. Mega cache.

• The first time, compute and cache

Page 74: Relate all the things!

I got cache. Mega cache.

• The first time, compute and cache• Internally, three cache engines built-in:

Page 75: Relate all the things!

I got cache. Mega cache.

• The first time, compute and cache• Internally, three cache engines built-in:

• YARPP_Cache_Tables

Page 76: Relate all the things!

I got cache. Mega cache.

• The first time, compute and cache• Internally, three cache engines built-in:

• YARPP_Cache_Tables

• YARPP_Cache_Postmeta

Page 77: Relate all the things!

I got cache. Mega cache.

• The first time, compute and cache• Internally, three cache engines built-in:

• YARPP_Cache_Tables

• YARPP_Cache_Postmeta

• define('YARPP_CACHE_TYPE','postmeta');

Page 78: Relate all the things!

I got cache. Mega cache.

• The first time, compute and cache• Internally, three cache engines built-in:

• YARPP_Cache_Tables

• YARPP_Cache_Postmeta

• define('YARPP_CACHE_TYPE','postmeta');

• YARPP_Cache_Bypass

Page 79: Relate all the things!

I got cache. Mega cache.

• The first time, compute and cache• Internally, three cache engines built-in:

• YARPP_Cache_Tables

• YARPP_Cache_Postmeta

• define('YARPP_CACHE_TYPE','postmeta');

• YARPP_Cache_Bypass

• Used in custom queries

Page 80: Relate all the things!

query_posts(’p=4024’) //=>SELECT wp_posts.*FROM wp_postsWHERE 1=1 AND wp_posts.ID = 4024 AND wp_posts.post_type = 'post'ORDER BY wp_posts.post_date DESC

Page 81: Relate all the things!

query_posts w/table cacheSELECT wp_posts.*, yarpp.scoreFROM wp_postsJOIN wp_yarpp_related_cache AS yarppON wp_posts.ID = yarpp.ID

WHERE 1=1 ANDyarpp.reference_ID = 4024 ANDwp_posts.post_type IN ('post')

ORDER BY yarpp.score DESC LIMIT 5

http://mitcho.com/blog/how-to/external-orders-in-wordpress-queries/

Page 82: Relate all the things!

query_posts w/list of IDsSELECT wp_posts.*,CASE wp_posts.IDWHEN 43 THEN 23.0 WHEN 1413 THEN 20.5WHEN 3448 THEN 19.7 WHEN 85 THEN 19.6WHEN 2203 THEN 19.0 END as score

FROM wp_postsWHERE 1=1 ANDwp_posts.ID in (43,1413,3448,85,2203) ANDwp_posts.post_type IN ('post')

ORDER BY score DESC LIMIT 5

Page 83: Relate all the things!

YARPP 3.5COMING SOON TO A

WORDPRESS NEAR YOU

Download 3.5b4:http://tinyurl.com/yarppversions

Page 84: Relate all the things!

Thank you!slides on http://slideshare.net/mitcho@themitcho, @yarpp