Version Description
Download this release
Release Info
Developer | mitchoyoshitaka |
Plugin | Yet Another Related Posts Plugin (YARPP) |
Version | 2.0.2 |
Comparing to | |
See all releases |
Code changes from version 1.5.1 to 2.0.2
- includes.php +104 -11
- magic.php +117 -81
- options.css +0 -5
- options.php +216 -54
- readme.txt +56 -25
- yarpp.php +7 -4
includes.php
CHANGED
@@ -10,13 +10,22 @@ $yarpp_value_options = array('threshold' => 5,
|
|
10 |
'after_post' => '</small>',
|
11 |
'before_related' => '<p>Related posts:<ol>',
|
12 |
'after_related' => '</ol></p>',
|
13 |
-
'no_results' => '<p>No related posts.</p>'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
$yarpp_binary_options = array('past_only' => true,
|
15 |
'show_score' => true,
|
16 |
'show_excerpt' => false,
|
17 |
'show_pass_post' => false,
|
18 |
'cross_relate' => false,
|
19 |
-
'auto_display' => true
|
|
|
20 |
|
21 |
function yarpp_enabled() {
|
22 |
global $wpdb;
|
@@ -36,21 +45,67 @@ function yarpp_activate() {
|
|
36 |
if (!yarpp_enabled()) {
|
37 |
$wpdb->query("ALTER TABLE $wpdb->posts ADD FULLTEXT `post_related` ( `post_name` , `post_content` )");
|
38 |
}
|
39 |
-
add_option('yarpp_version','
|
40 |
-
update_option('yarpp_version','
|
41 |
return 1;
|
42 |
}
|
43 |
|
44 |
function yarpp_upgrade_check() {
|
|
|
|
|
45 |
if (get_option('threshold') and get_option('limit') and get_option('len')) {
|
46 |
yarpp_activate(); // just to make sure, in case the plugin was just replaced and not deactivated / activated
|
47 |
echo '<div id="message" class="updated fade" style="background-color: rgb(207, 235, 247);"><h3>An important message from YARPP:</h3><p>Thank you for upgrading to YARPP 1.5. YARPP 1.5 adds "simple installation" which automagically prints a simple related posts display at the end of each single entry (permalink) page without tinkering with any theme files. As a previous YARPP user, you probably have already edited your theme files to your liking, so this "automatic display" feature has been turned off.</p><p>If you would like to use "automatic display," remove <code>related_posts</code> from your <code>single.php</code> file and turn on automatic display in the YARPP options. Make sure to adjust the new prefix and suffix preferences to your liking as well.</p><p>For more information, check out the <a href="http://mitcho.com/code/yarpp/">YARPP documentation</a>. (This message will not be displayed again.)</p></div>';
|
48 |
yarpp_upgrade_one_five();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
}
|
|
|
50 |
}
|
51 |
|
52 |
function yarpp_admin_menu() {
|
53 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
}
|
55 |
|
56 |
function yarpp_default($content) {
|
@@ -62,12 +117,35 @@ function yarpp_default($content) {
|
|
62 |
}
|
63 |
}
|
64 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
|
|
|
66 |
|
67 |
-
|
68 |
-
|
69 |
-
function apply_filters_without($tag, $string, $without) {
|
70 |
-
global $wp_filter, $merged_filters;
|
71 |
|
72 |
if ( !isset( $merged_filters[ $tag ] ) )
|
73 |
merge_filters($tag);
|
@@ -80,11 +158,14 @@ function apply_filters_without($tag, $string, $without) {
|
|
80 |
$args = func_get_args();
|
81 |
|
82 |
do{
|
83 |
-
foreach( (array) current($wp_filter[$tag]) as $the_ )
|
84 |
-
if ( !is_null($the_['function'])
|
|
|
85 |
$args[1] = $string;
|
|
|
86 |
$string = call_user_func_array($the_['function'], array_slice($args, 1, (int) $the_['accepted_args']));
|
87 |
}
|
|
|
88 |
|
89 |
} while ( next($wp_filter[$tag]) !== false );
|
90 |
|
@@ -112,4 +193,16 @@ function yarpp_upgrade_one_five() {
|
|
112 |
unset($yarpp_version);
|
113 |
}
|
114 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
115 |
?>
|
10 |
'after_post' => '</small>',
|
11 |
'before_related' => '<p>Related posts:<ol>',
|
12 |
'after_related' => '</ol></p>',
|
13 |
+
'no_results' => '<p>No related posts.</p>',
|
14 |
+
'title' => '2',
|
15 |
+
'body' => '2',
|
16 |
+
'categories' => '2',
|
17 |
+
'tags' => '2',
|
18 |
+
'distags' => '',
|
19 |
+
'discats' => '',
|
20 |
+
'order' => 'score DESC'
|
21 |
+
);
|
22 |
$yarpp_binary_options = array('past_only' => true,
|
23 |
'show_score' => true,
|
24 |
'show_excerpt' => false,
|
25 |
'show_pass_post' => false,
|
26 |
'cross_relate' => false,
|
27 |
+
'auto_display' => true,
|
28 |
+
'promote_yarpp' => false);
|
29 |
|
30 |
function yarpp_enabled() {
|
31 |
global $wpdb;
|
45 |
if (!yarpp_enabled()) {
|
46 |
$wpdb->query("ALTER TABLE $wpdb->posts ADD FULLTEXT `post_related` ( `post_name` , `post_content` )");
|
47 |
}
|
48 |
+
add_option('yarpp_version','2.02');
|
49 |
+
update_option('yarpp_version','2.02');
|
50 |
return 1;
|
51 |
}
|
52 |
|
53 |
function yarpp_upgrade_check() {
|
54 |
+
global $yarpp_value_options, $yarpp_binary_options;
|
55 |
+
|
56 |
if (get_option('threshold') and get_option('limit') and get_option('len')) {
|
57 |
yarpp_activate(); // just to make sure, in case the plugin was just replaced and not deactivated / activated
|
58 |
echo '<div id="message" class="updated fade" style="background-color: rgb(207, 235, 247);"><h3>An important message from YARPP:</h3><p>Thank you for upgrading to YARPP 1.5. YARPP 1.5 adds "simple installation" which automagically prints a simple related posts display at the end of each single entry (permalink) page without tinkering with any theme files. As a previous YARPP user, you probably have already edited your theme files to your liking, so this "automatic display" feature has been turned off.</p><p>If you would like to use "automatic display," remove <code>related_posts</code> from your <code>single.php</code> file and turn on automatic display in the YARPP options. Make sure to adjust the new prefix and suffix preferences to your liking as well.</p><p>For more information, check out the <a href="http://mitcho.com/code/yarpp/">YARPP documentation</a>. (This message will not be displayed again.)</p></div>';
|
59 |
yarpp_upgrade_one_five();
|
60 |
+
update_option('yarpp_version','1.5');
|
61 |
+
}
|
62 |
+
|
63 |
+
if (get_option('yarpp_version') < 2) {
|
64 |
+
foreach (array_keys($yarpp_value_options) as $option) {
|
65 |
+
if (!get_option('yarpp_'.$option))
|
66 |
+
add_option('yarpp_'.$option,$yarpp_value_options[$option]);
|
67 |
+
}
|
68 |
+
foreach (array_keys($yarpp_binary_options) as $option) {
|
69 |
+
if (!get_option('yarpp_'.$option))
|
70 |
+
add_option('yarpp_'.$option,$yarpp_binary_options[$option]);
|
71 |
+
}
|
72 |
+
|
73 |
+
echo '<div id="message" class="updated fade" style="background-color: rgb(207, 235, 247);"><h3>An important message from YARPP:</h3><p>Thank you for upgrading to YARPP 2.0. YARPP 2.0 adds the much requested ability to limit related entry results by certain tags or categories. 2.0 also brings more fine tuned control of the magic algorithm, letting you specify how the algorithm should consider or not consider entry content, titles, tags, and categories. Make sure to adjust the new settings to your liking and perhaps readjust your threshold.</p><p>For more information, check out the <a href="http://mitcho.com/code/yarpp/">YARPP documentation</a>. (This message will not be displayed again.)</p></div>';
|
74 |
+
update_option('yarpp_version','2.0');
|
75 |
+
}
|
76 |
+
|
77 |
+
if (get_option('yarpp_version') < 2.02) {
|
78 |
+
update_option('yarpp_version','2.02');
|
79 |
}
|
80 |
+
|
81 |
}
|
82 |
|
83 |
function yarpp_admin_menu() {
|
84 |
+
add_options_page('Related Posts (YARPP)', 'Related Posts (YARPP)', 8, 'yet-another-related-posts-plugin/options.php', 'yarpp_options_page');
|
85 |
+
//if (function_exists('add_submenu_page')) add_submenu_page('options-general.php', 'Related Posts (YARPP)', 'Related Posts (YARPP)', 8, 'yet-another-related-posts-plugin/options.php');
|
86 |
+
}
|
87 |
+
|
88 |
+
function yarpp_options_page() {
|
89 |
+
require(str_replace('includes.php','options.php',__FILE__));
|
90 |
+
}
|
91 |
+
|
92 |
+
// This function was written by tyok
|
93 |
+
function widget_yarpp_init() {
|
94 |
+
|
95 |
+
if ( !function_exists('register_sidebar_widget') || !function_exists('register_widget_control') )
|
96 |
+
return;
|
97 |
+
|
98 |
+
function widget_yarpp($args) {
|
99 |
+
extract($args);
|
100 |
+
global $wpdb, $post, $user_level;
|
101 |
+
if (get_option('yarpp_auto_display') and is_single()) {
|
102 |
+
echo $before_widget;
|
103 |
+
echo $before_title . 'Related Posts' . $after_title;
|
104 |
+
echo yarpp_related(array('post'),array());
|
105 |
+
echo $after_widget;
|
106 |
+
}
|
107 |
+
}
|
108 |
+
register_sidebar_widget(__('YARPP'), 'widget_yarpp');
|
109 |
}
|
110 |
|
111 |
function yarpp_default($content) {
|
117 |
}
|
118 |
}
|
119 |
|
120 |
+
/* new in 2.0! apply_filters_if_white (previously apply_filters_without) now has a blacklist. It's defined here. */
|
121 |
+
|
122 |
+
/* blacklisted so far:
|
123 |
+
- diggZEt
|
124 |
+
- WP-Syntax
|
125 |
+
- Viper's Video Quicktags
|
126 |
+
- WP-CodeBox
|
127 |
+
- WP shortcodes
|
128 |
+
*/
|
129 |
+
|
130 |
+
$yarpp_blacklist = array(null,'yarpp_default','diggZEt_AddBut','wp_syntax_before_filter','wp_syntax_after_filter','wp_codebox_before_filter','wp_codebox_after_filter','do_shortcode');
|
131 |
+
$yarpp_blackmethods = array(null,'addinlinejs','replacebbcode');
|
132 |
+
|
133 |
+
function yarpp_white($filter) {
|
134 |
+
global $yarpp_blacklist;
|
135 |
+
global $yarpp_blackmethods;
|
136 |
+
if (is_array($filter)) {
|
137 |
+
if (array_search($filter[1],$yarpp_blackmethods)) //print_r($filter[1]);
|
138 |
+
return false;
|
139 |
+
}
|
140 |
+
if (array_search($filter,$yarpp_blacklist)) //print_r($filter);
|
141 |
+
return false;
|
142 |
+
return true;
|
143 |
+
}
|
144 |
|
145 |
+
/* FYI, apply_filters_if_white was used here to avoid a loop in apply_filters('the_content') > yarpp_default() > yarpp_related() > current_post_keywords() > apply_filters('the_content').*/
|
146 |
|
147 |
+
function apply_filters_if_white($tag, $string) {
|
148 |
+
global $wp_filter, $merged_filters, $yarpp_blacklist;
|
|
|
|
|
149 |
|
150 |
if ( !isset( $merged_filters[ $tag ] ) )
|
151 |
merge_filters($tag);
|
158 |
$args = func_get_args();
|
159 |
|
160 |
do{
|
161 |
+
foreach( (array) current($wp_filter[$tag]) as $the_ ) {
|
162 |
+
if ( !is_null($the_['function'])
|
163 |
+
and yarpp_white($the_['function'])){ // HACK
|
164 |
$args[1] = $string;
|
165 |
+
$oldstring = $string;
|
166 |
$string = call_user_func_array($the_['function'], array_slice($args, 1, (int) $the_['accepted_args']));
|
167 |
}
|
168 |
+
}
|
169 |
|
170 |
} while ( next($wp_filter[$tag]) !== false );
|
171 |
|
193 |
unset($yarpp_version);
|
194 |
}
|
195 |
|
196 |
+
// upgrade to 1.5!
|
197 |
+
function yarpp_upgrade_one_six() {
|
198 |
+
global $wpdb;
|
199 |
+
}
|
200 |
+
|
201 |
+
define('LOREMIPSUM','Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Cras tincidunt justo a urna. Ut turpis. Phasellus convallis, odio sit amet cursus convallis, eros orci scelerisque velit, ut sodales neque nisl at ante. Suspendisse metus. Curabitur auctor pede quis mi. Pellentesque lorem justo, condimentum ac, dapibus sit amet, ornare et, erat. Quisque velit. Etiam sodales dui feugiat neque suscipit bibendum. Integer mattis. Nullam et ante non sem commodo malesuada. Pellentesque ultrices fermentum lectus. Maecenas hendrerit neque ac est. Fusce tortor mi, tristique sed, cursus at, pellentesque non, dui. Suspendisse potenti.');
|
202 |
+
|
203 |
+
function yarpp_excerpt($content,$length) {
|
204 |
+
preg_replace('/([,;.-]+)\s*/','\1 ',$content);
|
205 |
+
return implode(' ',array_slice(preg_split('/\s+/',$content),0,$length)).'...';
|
206 |
+
}
|
207 |
+
|
208 |
?>
|
magic.php
CHANGED
@@ -1,7 +1,29 @@
|
|
1 |
<?php
|
2 |
|
3 |
-
|
4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
/**
|
6 |
* Builds a word frequency list from the Wordpress post, and returns a string
|
7 |
* to be used in matching against the MySQL full-text index.
|
@@ -10,45 +32,17 @@
|
|
10 |
* the database.
|
11 |
* @return string The words
|
12 |
*/
|
13 |
-
function
|
14 |
-
global $post;
|
15 |
-
// An array of weightings, to make adjusting them easier.
|
16 |
-
$w = array(
|
17 |
-
'title' => 2,
|
18 |
-
'name' => 2,
|
19 |
-
'content' => 1,
|
20 |
-
'cat_name' => 3
|
21 |
-
);
|
22 |
-
|
23 |
-
/*
|
24 |
-
Thanks to http://www.eatdrinksleepmovabletype.com/tutorials/building_a_weighted_keyword_list/
|
25 |
-
for the basics for this code. It saved me much typing (or thinking) :)
|
26 |
-
*/
|
27 |
-
|
28 |
-
// This needs experimenting with. I've given post title and url a double
|
29 |
-
// weighting, changing this may give you better results
|
30 |
-
$string = str_repeat($post->post_title, $w['title'].' ').
|
31 |
-
str_repeat(str_replace('-', ' ', $post->post_name).' ', $w['name']).
|
32 |
-
str_repeat(strip_tags(apply_filters_without('the_content',$post->post_content,'yarpp_default')), $w['content'].' ');//mitcho: strip_tags
|
33 |
-
|
34 |
-
// Cat names don't help with the current query: the category names of other
|
35 |
-
// posts aren't retrieved by the query to be matched against (and can't be
|
36 |
-
// indexed)
|
37 |
-
// But I've left this in just in case...
|
38 |
-
$post_categories = get_the_category();
|
39 |
-
foreach ($post_categories as $cat) {
|
40 |
-
$string .= str_repeat($cat->cat_name.' ', $w['cat_name']);
|
41 |
-
}
|
42 |
|
43 |
-
|
|
|
|
|
44 |
$wordlist = preg_split('/\s*[\s+\.|\?|,|(|)|\-+|\'|\"|=|;|×|\$|\/|:|{|}]\s*/i', strtolower($string));
|
45 |
|
46 |
// Build an array of the unique words and number of times they occur.
|
47 |
$a = array_count_values($wordlist);
|
48 |
|
49 |
-
//Remove words that don't matter--"stop words."
|
50 |
-
$overusedwords = array( '', 'a', 'an', 'the', 'and', 'of', 'i', 'to', 'is', 'in', 'with', 'for', 'as', 'that', 'on', 'at', 'this', 'my', 'was', 'our', 'it', 'you', 'we', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '10', 'about', 'after', 'all', 'almost', 'along', 'also', 'amp', 'another', 'any', 'are', 'area', 'around', 'available', 'back', 'be', 'because', 'been', 'being', 'best', 'better', 'big', 'bit', 'both', 'but', 'by', 'c', 'came', 'can', 'capable', 'control', 'could', 'course', 'd', 'dan', 'day', 'decided', 'did', 'didn', 'different', 'div', 'do', 'doesn', 'don', 'down', 'drive', 'e', 'each', 'easily', 'easy', 'edition', 'end', 'enough', 'even', 'every', 'example', 'few', 'find', 'first', 'found', 'from', 'get', 'go', 'going', 'good', 'got', 'gt', 'had', 'hard', 'has', 'have', 'he', 'her', 'here', 'how', 'if', 'into', 'isn', 'just', 'know', 'last', 'left', 'li', 'like', 'little', 'll', 'long', 'look', 'lot', 'lt', 'm', 'made', 'make', 'many', 'mb', 'me', 'menu', 'might', 'mm', 'more', 'most', 'much', 'name', 'nbsp', 'need', 'new', 'no', 'not', 'now', 'number', 'off', 'old', 'one', 'only', 'or', 'original', 'other', 'out', 'over', 'part', 'place', 'point', 'pretty', 'probably', 'problem', 'put', 'quite', 'quot', 'r', 're', 'really', 'results', 'right', 's', 'same', 'saw', 'see', 'set', 'several', 'she', 'sherree', 'should', 'since', 'size', 'small', 'so', 'some', 'something', 'special', 'still', 'stuff', 'such', 'sure', 'system', 't', 'take', 'than', 'their', 'them', 'then', 'there', 'these', 'they', 'thing', 'things', 'think', 'those', 'though', 'through', 'time', 'today', 'together', 'too', 'took', 'two', 'up', 'us', 'use', 'used', 'using', 've', 'very', 'want', 'way', 'well', 'went', 'were', 'what', 'when', 'where', 'which', 'while', 'white', 'who', 'will', 'would', 'your');
|
51 |
-
|
52 |
// Remove the stop words from the list.
|
53 |
foreach ($overusedwords as $word) {
|
54 |
unset($a[$word]);
|
@@ -63,45 +57,100 @@ function current_post_keywords($num_to_ret = 20) {
|
|
63 |
|
64 |
}
|
65 |
|
66 |
-
function
|
67 |
-
global $wpdb, $post
|
68 |
-
|
|
|
69 |
|
70 |
// if cross_relate is set, override the type argument and make sure both matches are accepted in the sql query
|
71 |
if (get_option('yarpp_cross_relate')) $type = array('post','page');
|
72 |
|
73 |
-
//
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
74 |
$options = array('limit','threshold','before_title','after_title','show_excerpt','excerpt_length','before_post','after_post','show_pass_post','past_only','show_score');
|
75 |
$optvals = array();
|
76 |
foreach (array_keys($options) as $index) {
|
77 |
if (isset($args[$index+1])) {
|
78 |
$optvals[$options[$index]] = stripslashes($args[$index+1]);
|
79 |
} else {
|
80 |
-
$optvals[$options[$index]] = stripslashes(get_option('yarpp_'.$options[$index]));
|
81 |
}
|
82 |
}
|
83 |
extract($optvals);
|
84 |
-
|
85 |
-
// Fetch keywords
|
86 |
-
$terms = current_post_keywords();
|
87 |
-
|
88 |
-
// Make sure the post is not from the future
|
89 |
-
$time_difference = get_settings('gmt_offset');
|
90 |
-
$now = gmdate("Y-m-d H:i:s",(time()+($time_difference*3600)));
|
91 |
|
92 |
// Primary SQL query
|
93 |
|
94 |
-
$
|
95 |
-
. "MATCH (post_name, post_content) "
|
96 |
-
. "AGAINST ('$terms') AS score "
|
97 |
-
. "FROM $wpdb->posts WHERE "
|
98 |
-
. "post_type IN ('".implode("', '",$type)."') "
|
99 |
-
. "AND MATCH (post_name, post_content) AGAINST ('$terms') >= $threshold "
|
100 |
-
. "AND (post_status IN ( 'publish', 'static' ) && ID != '$post->ID') ";
|
101 |
-
if (past_only) { $sql .= "AND post_date <= '$now' "; }
|
102 |
-
if ($show_pass_post=='false') { $sql .= "AND post_password ='' "; }
|
103 |
-
$sql .= "ORDER BY score DESC LIMIT $limit";
|
104 |
-
$results = $wpdb->get_results($sql);
|
105 |
$output = '';
|
106 |
if ($results) {
|
107 |
foreach ($results as $result) {
|
@@ -109,15 +158,16 @@ function yarpp_related($type,$args,$echo = true) {
|
|
109 |
$permalink = get_permalink($result->ID);
|
110 |
$post_content = strip_tags($result->post_content);
|
111 |
$post_content = stripslashes($post_content);
|
112 |
-
$output .= $before_title .'<a href="'. $permalink .'" rel="bookmark" title="Permanent Link: ' . $title . '">' . $title . (($show_score and $user_level >= 8)? ' ('.round($result->score,3).')':'') . '</a>'
|
113 |
if ($show_excerpt) {
|
114 |
-
$
|
115 |
-
$ze = substr($ze, 0, strrpos($ze,' '));
|
116 |
-
$ze .= '...';
|
117 |
-
$output .= $before_post . $ze . $after_post;
|
118 |
}
|
|
|
119 |
}
|
120 |
-
$output = get_option('yarpp_before_related').$output.get_option('yarpp_after_related');
|
|
|
|
|
|
|
121 |
} else {
|
122 |
$output = get_option('yarpp_no_results');
|
123 |
}
|
@@ -127,33 +177,19 @@ function yarpp_related($type,$args,$echo = true) {
|
|
127 |
function yarpp_related_exist($type,$args) {
|
128 |
global $wpdb, $post;
|
129 |
|
130 |
-
if (get_option('yarpp_cross_relate')) $type = array('post','page');
|
131 |
-
|
132 |
$options = array('threshold','show_pass_post','past_only');
|
133 |
$optvals = array();
|
134 |
foreach (array_keys($options) as $index) {
|
135 |
if (isset($args[$index+1])) {
|
136 |
$optvals[$options[$index]] = stripslashes($args[$index+1]);
|
137 |
} else {
|
138 |
-
$optvals[$options[$index]] = stripslashes(get_option('yarpp_'.$options[$index]));
|
139 |
}
|
140 |
}
|
141 |
extract($optvals);
|
|
|
142 |
|
143 |
-
$
|
144 |
-
|
145 |
-
$time_difference = get_settings('gmt_offset');
|
146 |
-
$now = gmdate("Y-m-d H:i:s",(time()+($time_difference*3600)));
|
147 |
-
|
148 |
-
$sql = "SELECT COUNT(*) as count "
|
149 |
-
. "FROM $wpdb->posts WHERE "
|
150 |
-
. "post_type IN ('".implode("', '",$type)."') "
|
151 |
-
. "AND MATCH (post_name, post_content) AGAINST ('$terms') >= $threshold "
|
152 |
-
. "AND (post_status IN ( 'publish', 'static' ) && ID != '$post->ID') ";
|
153 |
-
if (past_only) { $sql .= "AND post_date <= '$now' "; }
|
154 |
-
if ($show_pass_post=='false') { $sql .= "AND post_password ='' "; }
|
155 |
-
|
156 |
-
$result = $wpdb->get_var($sql);
|
157 |
return $result > 0 ? true: false;
|
158 |
}
|
159 |
|
1 |
<?php
|
2 |
|
3 |
+
$overusedwords = array( '', 'a', 'an', 'the', 'and', 'of', 'i', 'to', 'is', 'in', 'with', 'for', 'as', 'that', 'on', 'at', 'this', 'my', 'was', 'our', 'it', 'you', 'we', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '10', 'about', 'after', 'all', 'almost', 'along', 'also', 'amp', 'another', 'any', 'are', 'area', 'around', 'available', 'back', 'be', 'because', 'been', 'being', 'best', 'better', 'big', 'bit', 'both', 'but', 'by', 'c', 'came', 'can', 'capable', 'control', 'could', 'course', 'd', 'dan', 'day', 'decided', 'did', 'didn', 'different', 'div', 'do', 'doesn', 'don', 'down', 'drive', 'e', 'each', 'easily', 'easy', 'edition', 'end', 'enough', 'even', 'every', 'example', 'few', 'find', 'first', 'found', 'from', 'get', 'go', 'going', 'good', 'got', 'gt', 'had', 'hard', 'has', 'have', 'he', 'her', 'here', 'how', 'if', 'into', 'isn', 'just', 'know', 'last', 'left', 'li', 'like', 'little', 'll', 'long', 'look', 'lot', 'lt', 'm', 'made', 'make', 'many', 'mb', 'me', 'menu', 'might', 'mm', 'more', 'most', 'much', 'name', 'nbsp', 'need', 'new', 'no', 'not', 'now', 'number', 'off', 'old', 'one', 'only', 'or', 'original', 'other', 'out', 'over', 'part', 'place', 'point', 'pretty', 'probably', 'problem', 'put', 'quite', 'quot', 'r', 're', 'really', 'results', 'right', 's', 'same', 'saw', 'see', 'set', 'several', 'she', 'sherree', 'should', 'since', 'size', 'small', 'so', 'some', 'something', 'special', 'still', 'stuff', 'such', 'sure', 'system', 't', 'take', 'than', 'their', 'them', 'then', 'there', 'these', 'they', 'thing', 'things', 'think', 'those', 'though', 'through', 'time', 'today', 'together', 'too', 'took', 'two', 'up', 'us', 'use', 'used', 'using', 've', 'very', 'want', 'way', 'well', 'went', 'were', 'what', 'when', 'where', 'which', 'while', 'white', 'who', 'will', 'would', 'your');
|
4 |
+
|
5 |
+
function post_title_keywords($num_to_ret = 20) {
|
6 |
+
global $post, $overusedwords;
|
7 |
+
$wordlist = preg_split('/\s*[\s+\.|\?|,|(|)|\-+|\'|\"|=|;|×|\$|\/|:|{|}]\s*/i', strtolower($post->post_title));
|
8 |
+
|
9 |
+
// Build an array of the unique words and number of times they occur.
|
10 |
+
$a = array_count_values($wordlist);
|
11 |
+
|
12 |
+
// Remove the stop words from the list.
|
13 |
+
foreach ($overusedwords as $word) {
|
14 |
+
unset($a[$word]);
|
15 |
+
}
|
16 |
+
arsort($a, SORT_NUMERIC);
|
17 |
+
|
18 |
+
$num_words = count($a);
|
19 |
+
$num_to_ret = $num_words > $num_to_ret ? $num_to_ret : $num_words;
|
20 |
+
|
21 |
+
$outwords = array_slice($a, 0, $num_to_ret);
|
22 |
+
return implode(' ', array_keys($outwords));
|
23 |
+
}
|
24 |
+
|
25 |
+
// post_body_keywords()
|
26 |
+
// Based on create_post_keywords by Peter Bowyer with major changes by mitcho
|
27 |
/**
|
28 |
* Builds a word frequency list from the Wordpress post, and returns a string
|
29 |
* to be used in matching against the MySQL full-text index.
|
32 |
* the database.
|
33 |
* @return string The words
|
34 |
*/
|
35 |
+
function post_body_keywords($num_to_ret = 20) {
|
36 |
+
global $post, $overusedwords;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
|
38 |
+
$string = strip_tags(apply_filters_if_white('the_content',$post->post_content));
|
39 |
+
|
40 |
+
// Remove punctuation and split
|
41 |
$wordlist = preg_split('/\s*[\s+\.|\?|,|(|)|\-+|\'|\"|=|;|×|\$|\/|:|{|}]\s*/i', strtolower($string));
|
42 |
|
43 |
// Build an array of the unique words and number of times they occur.
|
44 |
$a = array_count_values($wordlist);
|
45 |
|
|
|
|
|
|
|
46 |
// Remove the stop words from the list.
|
47 |
foreach ($overusedwords as $word) {
|
48 |
unset($a[$word]);
|
57 |
|
58 |
}
|
59 |
|
60 |
+
function yarpp_sql($options_array,$giveresults = true) {
|
61 |
+
global $wpdb, $post;
|
62 |
+
|
63 |
+
extract($options_array);
|
64 |
|
65 |
// if cross_relate is set, override the type argument and make sure both matches are accepted in the sql query
|
66 |
if (get_option('yarpp_cross_relate')) $type = array('post','page');
|
67 |
|
68 |
+
// Fetch keywords
|
69 |
+
$body_terms = post_body_keywords();
|
70 |
+
$title_terms = post_title_keywords();
|
71 |
+
|
72 |
+
// Make sure the post is not from the future
|
73 |
+
$time_difference = get_settings('gmt_offset');
|
74 |
+
$now = gmdate("Y-m-d H:i:s",(time()+($time_difference*3600)));
|
75 |
+
|
76 |
+
// get weights
|
77 |
+
|
78 |
+
$bodyweight = ((get_option('yarpp_body') == 3)?3:((get_option('yarpp_body') == 2)?1:0));
|
79 |
+
$titleweight = ((get_option('yarpp_title') == 3)?3:((get_option('yarpp_title') == 2)?1:0));
|
80 |
+
$tagweight = ((get_option('yarpp_tags') != 1)?1:0);
|
81 |
+
$catweight = ((get_option('yarpp_categories') != 1)?1:0);
|
82 |
+
|
83 |
+
$totalweight = $bodyweight + $titleweight + $tagweight + $catweight;
|
84 |
+
|
85 |
+
$weightedthresh = $threshold/($totalweight + 0.1);
|
86 |
+
|
87 |
+
// get disallowed categories and tags
|
88 |
+
|
89 |
+
$disterms = implode(',', array_filter(array_merge(explode(',',get_option('yarpp_discats')),explode(',',get_option('yarpp_distags'))),'is_numeric'));
|
90 |
+
|
91 |
+
|
92 |
+
$sql = "SELECT *, (bodyscore * $bodyweight + titlescore * $titleweight + tagscore * $tagweight + catscore * $catweight) AS score
|
93 |
+
from (
|
94 |
+
select ID, post_title, post_date, post_content, (MATCH (post_content) AGAINST ('udon yilan great diner pizza steak soup taipei store aaron meal real american 0 night half market classic taiwanese recommended')) as bodyscore, (MATCH (post_title) AGAINST ('ate food')) as titlescore, ifnull(catscore,0) as catscore, ifnull(tagscore,0) as tagscore
|
95 |
+
from $wpdb->posts
|
96 |
+
left join (
|
97 |
+
select count(*) as block, object_id from $wpdb->term_relationships natural join $wpdb->term_taxonomy natural join $wpdb->terms
|
98 |
+
where $wpdb->terms.term_id in ($disterms)
|
99 |
+
group by object_id
|
100 |
+
) as poolblock on ($wpdb->posts.ID = poolblock.object_id)
|
101 |
+
left join (
|
102 |
+
select count(*) as tagscore, object_id from $wpdb->term_relationships natural join $wpdb->term_taxonomy
|
103 |
+
where $wpdb->term_taxonomy.taxonomy = 'post_tag'
|
104 |
+
and $wpdb->term_taxonomy.term_taxonomy_id in (select term_taxonomy_id from $wpdb->term_relationships where object_id = '$post->ID')
|
105 |
+
group by object_id
|
106 |
+
) as matchtags on ($wpdb->posts.ID = matchtags.object_id)
|
107 |
+
left join (
|
108 |
+
select count(*) as catscore, object_id from $wpdb->term_relationships natural join $wpdb->term_taxonomy
|
109 |
+
where $wpdb->term_taxonomy.taxonomy = 'category'
|
110 |
+
and $wpdb->term_taxonomy.term_taxonomy_id in (select term_taxonomy_id from $wpdb->term_relationships where object_id = '$post->ID')
|
111 |
+
group by object_id
|
112 |
+
) as matchcats on ($wpdb->posts.ID = matchcats.object_id)
|
113 |
+
where ((post_status IN ( 'publish', 'static' ) && ID != '$post->ID')"
|
114 |
+
.($past_only ?" and post_date <= '$now' ":' ')
|
115 |
+
.((!$show_pass_post)?" and post_password ='' ":' ')
|
116 |
+
." and post_type IN ('".implode("', '",$type)."')
|
117 |
+
and block IS NULL
|
118 |
+
)
|
119 |
+
) as rawscores
|
120 |
+
where (bodyscore * $bodyweight + titlescore * $titleweight + tagscore * $tagweight + catscore * $catweight) >= $threshold"
|
121 |
+
.((get_option('yarpp_categories') == 3)?' and catscore >= 1':'')
|
122 |
+
.((get_option('yarpp_categories') == 4)?' and catscore >= 2':'')
|
123 |
+
.((get_option('yarpp_tags') == 3)?' and tagscore >= 1':'')
|
124 |
+
.((get_option('yarpp_tags') == 4)?' and tagscore >= 2':'')
|
125 |
+
." order by ".((get_option('yarpp_order')?get_option('yarpp_order'):"score desc"))." limit $limit";
|
126 |
+
|
127 |
+
if (!$giveresults) {
|
128 |
+
$sql = 'select count(*) from ('.$sql.')';
|
129 |
+
}
|
130 |
+
|
131 |
+
return $sql;
|
132 |
+
}
|
133 |
+
|
134 |
+
function yarpp_related($type,$args,$echo = true) {
|
135 |
+
global $wpdb, $post, $user_level;
|
136 |
+
get_currentuserinfo();
|
137 |
+
|
138 |
+
// get options
|
139 |
$options = array('limit','threshold','before_title','after_title','show_excerpt','excerpt_length','before_post','after_post','show_pass_post','past_only','show_score');
|
140 |
$optvals = array();
|
141 |
foreach (array_keys($options) as $index) {
|
142 |
if (isset($args[$index+1])) {
|
143 |
$optvals[$options[$index]] = stripslashes($args[$index+1]);
|
144 |
} else {
|
145 |
+
$optvals[$options[$index]] = stripslashes(stripslashes(get_option('yarpp_'.$options[$index])));
|
146 |
}
|
147 |
}
|
148 |
extract($optvals);
|
149 |
+
$optvals['type'] = $type;
|
|
|
|
|
|
|
|
|
|
|
|
|
150 |
|
151 |
// Primary SQL query
|
152 |
|
153 |
+
$results = $wpdb->get_results(yarpp_sql($optvals));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
154 |
$output = '';
|
155 |
if ($results) {
|
156 |
foreach ($results as $result) {
|
158 |
$permalink = get_permalink($result->ID);
|
159 |
$post_content = strip_tags($result->post_content);
|
160 |
$post_content = stripslashes($post_content);
|
161 |
+
$output .= $before_title .'<a href="'. $permalink .'" rel="bookmark" title="Permanent Link: ' . $title . '">' . $title . (($show_score and $user_level >= 8)? ' ('.round($result->score,3).')':'') . '</a>';
|
162 |
if ($show_excerpt) {
|
163 |
+
$output .= $before_post . yarpp_excerpt($post_content,$excerpt_length) . $after_post;
|
|
|
|
|
|
|
164 |
}
|
165 |
+
$output .= $after_title;
|
166 |
}
|
167 |
+
$output = stripslashes(stripslashes(get_option('yarpp_before_related'))).$output.stripslashes(stripslashes(get_option('yarpp_after_related')));
|
168 |
+
if (get_option('yarpp_promote_yarpp'))
|
169 |
+
$output .= "\n<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>";
|
170 |
+
|
171 |
} else {
|
172 |
$output = get_option('yarpp_no_results');
|
173 |
}
|
177 |
function yarpp_related_exist($type,$args) {
|
178 |
global $wpdb, $post;
|
179 |
|
|
|
|
|
180 |
$options = array('threshold','show_pass_post','past_only');
|
181 |
$optvals = array();
|
182 |
foreach (array_keys($options) as $index) {
|
183 |
if (isset($args[$index+1])) {
|
184 |
$optvals[$options[$index]] = stripslashes($args[$index+1]);
|
185 |
} else {
|
186 |
+
$optvals[$options[$index]] = stripslashes(stripslashes(get_option('yarpp_'.$options[$index])));
|
187 |
}
|
188 |
}
|
189 |
extract($optvals);
|
190 |
+
$optvals['type'] = $type;
|
191 |
|
192 |
+
$result = $wpdb->get_var(yarpp_sql($optvals,false));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
193 |
return $result > 0 ? true: false;
|
194 |
}
|
195 |
|
options.css
CHANGED
@@ -20,9 +20,4 @@ a.info:hover span {
|
|
20 |
background-color:#ccc;
|
21 |
color:#000;
|
22 |
padding:4px;
|
23 |
-
}
|
24 |
-
|
25 |
-
span.new {
|
26 |
-
color: red;
|
27 |
-
size: 80%;
|
28 |
}
|
20 |
background-color:#ccc;
|
21 |
color:#000;
|
22 |
padding:4px;
|
|
|
|
|
|
|
|
|
|
|
23 |
}
|
options.php
CHANGED
@@ -1,101 +1,193 @@
|
|
1 |
<?php
|
2 |
// Begin Related Posts Options
|
3 |
|
4 |
-
global $yarpp_value_options, $yarpp_binary_options;
|
5 |
if (!yarpp_enabled()) {
|
6 |
echo '<div class="updated">';
|
7 |
if (yarpp_activate()) echo 'The YARPP database had an error but has been fixed.';
|
8 |
echo '</div>';
|
9 |
}
|
10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
if (isset($_POST['update_yarpp'])) {
|
12 |
foreach (array_keys($yarpp_value_options) as $option) {
|
13 |
-
update_option('yarpp_'.$option
|
|
|
|
|
|
|
|
|
|
|
14 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
foreach (array_keys($yarpp_binary_options) as $option) {
|
16 |
(isset($_POST[$option])) ? update_option('yarpp_'.$option,true) : update_option('yarpp_'.$option,false);
|
17 |
}
|
18 |
echo '<div id="message" class="updated fade" style="background-color: rgb(207, 235, 247);"><p>Options saved!</p></div>';
|
19 |
}
|
20 |
|
21 |
-
function checkbox($option,$desc,$tr="<tr>
|
22 |
-
<
|
23 |
-
echo " $tr<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
<td>
|
25 |
-
<input $inputplus type='
|
|
|
|
|
|
|
26 |
</td>
|
27 |
</tr>";
|
28 |
}
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
|
|
|
|
|
|
|
|
|
|
33 |
</tr>";
|
34 |
}
|
35 |
|
36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
|
|
|
38 |
<script type="text/javascript">
|
|
|
|
|
39 |
var css=document.createElement("link");
|
40 |
css.setAttribute("rel", "stylesheet");
|
41 |
css.setAttribute("type", "text/css");
|
42 |
css.setAttribute("href", "../wp-content/plugins/yet-another-related-posts-plugin/options.css");
|
43 |
document.getElementsByTagName("head")[0].appendChild(css);
|
|
|
44 |
</script>
|
45 |
|
46 |
<div class="wrap">
|
47 |
-
<
|
48 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
<form method="post">
|
50 |
-
<fieldset class="options">
|
51 |
-
<h3>"Relatedness" options</h3>
|
52 |
-
<p>YARPP is different than the <a href="http://wasabi.pbwiki.com/Related%20Entries">previous plugins it is based on</a> as it limits the related posts list by (1) a maximum number and (2) a <em>match threshold</em>. <a href="#" class='info'>more><span>The higher the match threshold, the more restrictive, and you get less related posts overall. The default match threshold is 5. If you want to find an appropriate match threshhold, I recommend you turn on the "show admins the match scores" setting below. That way, you can see what kinds of related posts are being picked up and with what kind of match scores, and determine an appropriate threshold for your site.</span></a></p>
|
53 |
-
|
54 |
-
<table class="optiontable editform" width="100%" scope="row">
|
55 |
-
<?php textbox('limit','Maximum number of related posts:')?>
|
56 |
-
<?php textbox('threshold','Match threshold:')?>
|
57 |
-
<?php checkbox('cross_relate',"Cross-relate posts and pages? <a href='#' class='info'>more><span>When the \"Cross-relate posts and pages\" option is selected, the <code>related_posts()</code>, <code>related_pagaes()</code>, and <code>related_entries()</code> all will give the same output, returning both related pages and posts.</span></a>"); ?>
|
58 |
|
59 |
-
</table>
|
60 |
-
<h3>Display options</h3>
|
61 |
-
<table class="optiontable editform" width="100%" scope="row">
|
62 |
-
<?php checkbox('auto_display',"Automatically display related posts? <span class='red'>NEW!</span> <a href='#' class='info'>more><span>This option automatically displays related posts right after the content on single entry pages. If this option is off, you will need to manually insert <code>related_posts()</code> or variants into your theme files.</span></a>"); ?>
|
63 |
-
<tr>
|
64 |
-
<td colspan='2'><label for="before_related">Before</label> / <label for="after_related">after related entries </label>:</td>
|
65 |
-
<td><input name="before_related" type="text" id="before_related" value="<?php echo htmlspecialchars(stripslashes(get_option('yarpp_before_related'))); ?>" size="10" /> / <input name="after_related" type="text" id="after_related" value="<?php echo htmlspecialchars(stripslashes(get_option('yarpp_after_related'))); ?>" size="10" /><em><small> For example: <ol></ol> or <div></div></small></em>
|
66 |
-
</td>
|
67 |
-
</tr>
|
68 |
-
<tr>
|
69 |
-
<td colspan='2'><label for="before_title">Before</label> / <label for="after_title">after each post </label>:</td>
|
70 |
-
<td><input name="before_title" type="text" id="before_title" value="<?php echo htmlspecialchars(stripslashes(get_option('yarpp_before_title'))); ?>" size="10" /> / <input name="after_title" type="text" id="after_title" value="<?php echo htmlspecialchars(stripslashes(get_option('yarpp_after_title'))); ?>" size="10" /><em><small> For example: <li></li> or <dl></dl></small></em>
|
71 |
-
</td>
|
72 |
-
</tr>
|
73 |
-
<?php checkbox('show_excerpt',"Show excerpt?","<tr>
|
74 |
-
<td colspan='2'>",' onclick="javascript:excerpt()"'); ?>
|
75 |
-
<?php textbox('excerpt_length','Excerpt length (No. of words):',null,"<tr name='excerpted'>
|
76 |
-
<td style='background-color: gray; width: .3px;'> </td><td>")?>
|
77 |
-
|
78 |
-
<tr name="excerpted">
|
79 |
-
<td style='background-color: gray; width: 3px;'> </td><td><label for="before_post">Before</label> / <label for="after_post">After</label> (Excerpt):</td>
|
80 |
-
<td><input name="before_post" type="text" id="before_post" value="<?php echo htmlspecialchars(stripslashes(get_option('yarpp_before_post'))); ?>" size="10" /> / <input name="after_post" type="text" id="after_post" value="<?php echo htmlspecialchars(stripslashes(get_option('yarpp_after_post'))); ?>" size="10" /><em><small> For example: <li></li> or <dl></dl></small></em>
|
81 |
-
</td>
|
82 |
-
</tr>
|
83 |
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
88 |
</table>
|
89 |
-
</fieldset>
|
90 |
|
91 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
92 |
|
93 |
-
|
|
|
|
|
|
|
|
|
94 |
|
95 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
96 |
<script language="javascript">
|
|
|
97 |
function excerpt() {
|
98 |
-
if (!document.getElementsByName('show_excerpt')[0].checked) {
|
99 |
document.getElementsByName('excerpted')[0].style.display = 'none';
|
100 |
document.getElementsByName('excerpted')[1].style.display = 'none';
|
101 |
} else {
|
@@ -104,8 +196,78 @@ document.getElementsByTagName("head")[0].appendChild(css);
|
|
104 |
}
|
105 |
}
|
106 |
excerpt();
|
|
|
107 |
</script>
|
108 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
109 |
<?php
|
110 |
|
111 |
// End Related Posts Options
|
1 |
<?php
|
2 |
// Begin Related Posts Options
|
3 |
|
4 |
+
global $wpdb, $yarpp_value_options, $yarpp_binary_options;
|
5 |
if (!yarpp_enabled()) {
|
6 |
echo '<div class="updated">';
|
7 |
if (yarpp_activate()) echo 'The YARPP database had an error but has been fixed.';
|
8 |
echo '</div>';
|
9 |
}
|
10 |
|
11 |
+
//compute $tagmap
|
12 |
+
$tagmap = array();
|
13 |
+
foreach ($wpdb->get_results("select $wpdb->terms.term_id, name from $wpdb->terms natural join $wpdb->term_taxonomy where $wpdb->term_taxonomy.taxonomy = 'category'") as $tag) {
|
14 |
+
$tagmap[$tag->term_id] = strtolower($tag->name);
|
15 |
+
}
|
16 |
+
|
17 |
+
function yarpp_mapthetag($id) {
|
18 |
+
global $tagmap;
|
19 |
+
return $tagmap[$id];
|
20 |
+
}
|
21 |
+
function yarpp_unmapthetag($name) {
|
22 |
+
global $tagmap;
|
23 |
+
$untagmap = array_flip($tagmap);
|
24 |
+
return $untagmap[$name];
|
25 |
+
}
|
26 |
+
|
27 |
if (isset($_POST['update_yarpp'])) {
|
28 |
foreach (array_keys($yarpp_value_options) as $option) {
|
29 |
+
update_option('yarpp_'.$option,addslashes($_POST[$option]));
|
30 |
+
}
|
31 |
+
if (isset($_POST['discats'])) {
|
32 |
+
update_option('yarpp_discats',implode(',',array_keys($_POST['discats']))); // discats is different
|
33 |
+
} else {
|
34 |
+
update_option('yarpp_discats','');
|
35 |
}
|
36 |
+
|
37 |
+
if (isset($_POST['distags'])) {
|
38 |
+
update_option('yarpp_distags',implode(',',array_keys($_POST['distags']))); // distags is also different
|
39 |
+
} else {
|
40 |
+
update_option('yarpp_distags','');
|
41 |
+
}
|
42 |
+
//update_option('yarpp_distags',implode(',',array_map('yarpp_unmapthetag',preg_split('!\s*[;,]\s*!',strtolower($_POST['distags']))))); // distags is even more different
|
43 |
+
|
44 |
foreach (array_keys($yarpp_binary_options) as $option) {
|
45 |
(isset($_POST[$option])) ? update_option('yarpp_'.$option,true) : update_option('yarpp_'.$option,false);
|
46 |
}
|
47 |
echo '<div id="message" class="updated fade" style="background-color: rgb(207, 235, 247);"><p>Options saved!</p></div>';
|
48 |
}
|
49 |
|
50 |
+
function checkbox($option,$desc,$tr="<tr valign='top'>
|
51 |
+
<th class='th-full' colspan='2' scope='row'>",$inputplus = '',$thplus='') {
|
52 |
+
echo " $tr<input $inputplus type='checkbox' name='$option' value='true'". ((get_option('yarpp_'.$option)) ? ' checked="checked"': '' )." /> $desc</th>$thplus
|
53 |
+
</tr>";
|
54 |
+
}
|
55 |
+
function textbox($option,$desc,$size=2,$tr="<tr valign='top'>
|
56 |
+
<th scope='row'>") {
|
57 |
+
echo " $tr$desc</th>
|
58 |
+
<td><input name='$option' type='text' id='$option' value='".htmlspecialchars(stripslashes(get_option('yarpp_'.$option)))."' size='$size' /></td>
|
59 |
+
</tr>";
|
60 |
+
}
|
61 |
+
function importance($option,$desc,$type='word',$tr="<tr valign='top'>
|
62 |
+
<th scope='row'>",$inputplus = '') {
|
63 |
+
echo " $tr$desc</th>
|
64 |
<td>
|
65 |
+
<input $inputplus type='radio' name='$option' value='1'". ((get_option('yarpp_'.$option) == 1) ? ' checked="checked"': '' )." /> do not consider
|
66 |
+
<input $inputplus type='radio' name='$option' value='2'". ((get_option('yarpp_'.$option) == 2) ? ' checked="checked"': '' )." /> consider
|
67 |
+
<input $inputplus type='radio' name='$option' value='3'". ((get_option('yarpp_'.$option) == 3) ? ' checked="checked"': '' )." /> require at least one $type in common
|
68 |
+
<input $inputplus type='radio' name='$option' value='4'". ((get_option('yarpp_'.$option) == 4) ? ' checked="checked"': '' )." /> require more than one $type in common
|
69 |
</td>
|
70 |
</tr>";
|
71 |
}
|
72 |
+
|
73 |
+
function importance2($option,$desc,$type='word',$tr="<tr valign='top'>
|
74 |
+
<th scope='row'>",$inputplus = '') {
|
75 |
+
echo " $tr$desc</th>
|
76 |
+
<td>
|
77 |
+
<input $inputplus type='radio' name='$option' value='1'". ((get_option('yarpp_'.$option) == 1) ? ' checked="checked"': '' )." /> do not consider
|
78 |
+
<input $inputplus type='radio' name='$option' value='2'". ((get_option('yarpp_'.$option) == 2) ? ' checked="checked"': '' )." /> consider
|
79 |
+
<input $inputplus type='radio' name='$option' value='3'". ((get_option('yarpp_'.$option) == 3) ? ' checked="checked"': '' )." /> consider with extra weight
|
80 |
+
</td>
|
81 |
</tr>";
|
82 |
}
|
83 |
|
84 |
+
function select($option,$desc,$type='word',$tr="<tr valign='top'>
|
85 |
+
<th scope='row'>",$inputplus = '') {
|
86 |
+
echo " $tr$desc</th>
|
87 |
+
<td>
|
88 |
+
<input $inputplus type='radio' name='$option' value='1'". ((get_option('yarpp_'.$option) == 1) ? ' checked="checked"': '' )." /> do not consider
|
89 |
+
<input $inputplus type='radio' name='$option' value='2'". ((get_option('yarpp_'.$option) == 2) ? ' checked="checked"': '' )." /> consider
|
90 |
+
<input $inputplus type='radio' name='$option' value='3'". ((get_option('yarpp_'.$option) == 3) ? ' checked="checked"': '' )." /> require at least one $type in common
|
91 |
+
<input $inputplus type='radio' name='$option' value='4'". ((get_option('yarpp_'.$option) == 4) ? ' checked="checked"': '' )." /> require more than one $type in common
|
92 |
+
</td>
|
93 |
+
</tr>";
|
94 |
+
}
|
95 |
|
96 |
+
?>
|
97 |
<script type="text/javascript">
|
98 |
+
//<![CDATA[
|
99 |
+
|
100 |
var css=document.createElement("link");
|
101 |
css.setAttribute("rel", "stylesheet");
|
102 |
css.setAttribute("type", "text/css");
|
103 |
css.setAttribute("href", "../wp-content/plugins/yet-another-related-posts-plugin/options.css");
|
104 |
document.getElementsByTagName("head")[0].appendChild(css);
|
105 |
+
//]]>
|
106 |
</script>
|
107 |
|
108 |
<div class="wrap">
|
109 |
+
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
|
110 |
+
<input type="hidden" name="cmd" value="_donations" />
|
111 |
+
<input type="hidden" name="business" value="mitcho@mitcho.com" />
|
112 |
+
<input type="hidden" name="item_name" value="Yet Another Related Posts Plugin" />
|
113 |
+
<input type="hidden" name="no_shipping" value="1" />
|
114 |
+
<input type="hidden" name="return" value="http://mitcho.com/code/yarpp/" />
|
115 |
+
<input type="hidden" name="cancel_return" value="http://mitcho.com/code/yarpp/" />
|
116 |
+
<input type="hidden" name="cn" value="Optional Comment" />
|
117 |
+
<input type="hidden" name="currency_code" value="USD" />
|
118 |
+
<input type="hidden" name="tax" value="0" />
|
119 |
+
<input type="hidden" name="lc" value="US" />
|
120 |
+
<input type="hidden" name="bn" value="PP-DonationsBF" />
|
121 |
+
|
122 |
+
<h2>
|
123 |
+
<input type="image" src="https://www.paypal.com/en_US/i/btn/x-click-but04.gif" name="submit" alt="Make payments with PayPal - it's fast, free and secure!" title="Donate to mitcho (Michael Yoshitaka Erlewine) for this plugin via PayPal" style="float:right" />
|
124 |
+
Yet Another Related Posts Plugin Options <small><?php echo get_option('yarpp_version'); ?></small>
|
125 |
+
</h2>
|
126 |
+
</form>
|
127 |
+
|
128 |
<form method="post">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
129 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
130 |
|
131 |
+
<p><small>by <a href="http://mitcho.com/code/">mitcho (Michael 芳貴 Erlewine)</a> and based on the fabulous work of <a href="http://peter.mapledesign.co.uk/weblog/archives/wordpress-related-posts-plugin">Peter Bower</a>, <a href="http://wasabi.pbwiki.com/Related%20Entries">Alexander Malov & Mike Lu</a>.</small></p>
|
132 |
+
|
133 |
+
|
134 |
+
<!--The Pool-->
|
135 |
+
<h3>"The Pool"</h3>
|
136 |
+
<p>"The Pool" refers to the pool of posts and pages that are candidates for display as related to the current entry.</p>
|
137 |
+
|
138 |
+
<table class="form-table">
|
139 |
+
<tbody>
|
140 |
+
<tr valign='top'>
|
141 |
+
<th scope='row'>Disallow by category: <span style='color:red;'>NEW!</span></th><td><div style="overflow:auto;max-height:100px;">
|
142 |
+
<?php
|
143 |
+
$discats = explode(',',get_option('yarpp_discats'));
|
144 |
+
array_unshift($discats,' ');
|
145 |
+
foreach ($wpdb->get_results("select $wpdb->terms.term_id, name from $wpdb->terms natural join $wpdb->term_taxonomy where $wpdb->term_taxonomy.taxonomy = 'category' order by name") as $cat) {
|
146 |
+
echo "<input type='checkbox' name='discats[$cat->term_id]' value='true'". (array_search($cat->term_id,$discats) ? ' checked="checked"': '' )." /> <label for='discats[$cat->term_id]'>$cat->name</label> ";
|
147 |
+
}?>
|
148 |
+
</div></td>
|
149 |
+
</tr>
|
150 |
+
<tr valign='top'>
|
151 |
+
<th scope='row'>Disallow by tag: <span style='color:red;'>NEW!</span></th>
|
152 |
+
<td><div style="overflow:auto;max-height:100px;"><!--Enter tags to use to block entries. Delimit with commas. Tags that do not currently exist will be ignored.<br /><input name='distags' type='text' id='$option' value='<?php implode(",",array_map("yarpp_mapthetag",explode(",",htmlspecialchars(stripslashes(get_option('yarpp_'.$option))))));?>' size='40' />-->
|
153 |
+
<?php
|
154 |
+
$distags = explode(',',get_option('yarpp_distags'));
|
155 |
+
array_unshift($distags,' ');
|
156 |
+
foreach ($wpdb->get_results("select $wpdb->terms.term_id, name from $wpdb->terms natural join $wpdb->term_taxonomy where $wpdb->term_taxonomy.taxonomy = 'post_tag' order by name") as $tag) {
|
157 |
+
echo "<input type='checkbox' name='distags[$tag->term_id]' value='true'". (array_search($tag->term_id,$distags) ? ' checked="checked"': '' )." /> <label for='distags[$tag->term_id]'>$tag->name</label> ";
|
158 |
+
}?>
|
159 |
+
</div></td>
|
160 |
+
</tr>
|
161 |
+
</tbody>
|
162 |
</table>
|
|
|
163 |
|
164 |
+
<!-- Relatedness -->
|
165 |
+
<h3>"Relatedness" options</h3>
|
166 |
+
<p>YARPP is different than the <a href="http://wasabi.pbwiki.com/Related%20Entries">previous plugins it is based on</a> as it limits the related posts list by (1) a maximum number and (2) a <em>match threshold</em>. <a href="#" class='info'>more><span>The higher the match threshold, the more restrictive, and you get less related posts overall. The default match threshold is 5. If you want to find an appropriate match threshhold, I recommend you turn on the "show admins the match scores" setting below. That way, you can see what kinds of related posts are being picked up and with what kind of match scores, and determine an appropriate threshold for your site.</span></a></p>
|
167 |
+
|
168 |
+
<table class="form-table">
|
169 |
+
<tbody>
|
170 |
+
<?php textbox('limit','Maximum number of related posts:')?>
|
171 |
|
172 |
+
<!-- <div id="mySlider"><span>do not consider</span>
|
173 |
+
<span>consider</span>
|
174 |
+
<span>require</span>
|
175 |
+
<span>require multiple</span>
|
176 |
+
</div>-->
|
177 |
|
178 |
+
<?php textbox('threshold','Match threshold:')?>
|
179 |
+
<?php importance2('title',"Titles: <span style='color:red;'>NEW!</span>")?>
|
180 |
+
<?php importance2('body',"Bodies: <span style='color:red;'>NEW!</span>")?>
|
181 |
+
<?php importance('tags',"Tags: <span style='color:red;'>NEW!</span>",'tag')?>
|
182 |
+
<?php importance('categories',"Categories: <span style='color:red;'>NEW!</span>",'category')?>
|
183 |
+
<?php checkbox('cross_relate',"Cross-relate posts and pages? <a href='#' class='info'>more><span>When the \"Cross-relate posts and pages\" option is selected, the <code>related_posts()</code>, <code>related_pagaes()</code>, and <code>related_entries()</code> all will give the same output, returning both related pages and posts.</span></a>"); ?>
|
184 |
+
</tbody>
|
185 |
+
</table>
|
186 |
+
|
187 |
<script language="javascript">
|
188 |
+
//<![CDATA[
|
189 |
function excerpt() {
|
190 |
+
if (!(document.getElementsByName('show_excerpt')[0].checked)) {
|
191 |
document.getElementsByName('excerpted')[0].style.display = 'none';
|
192 |
document.getElementsByName('excerpted')[1].style.display = 'none';
|
193 |
} else {
|
196 |
}
|
197 |
}
|
198 |
excerpt();
|
199 |
+
//]]!>
|
200 |
</script>
|
201 |
|
202 |
+
|
203 |
+
<!-- Display options -->
|
204 |
+
<h3>Display options</h3>
|
205 |
+
|
206 |
+
<table class="form-table">
|
207 |
+
<?php
|
208 |
+
// construct the demo code based on current preferences
|
209 |
+
|
210 |
+
$democode = stripslashes(htmlspecialchars(stripslashes(get_option('yarpp_before_related'))))."
|
211 |
+
";
|
212 |
+
for ($i=1;$i<=get_option('yarpp_limit');$i++) {
|
213 |
+
$democode .= stripslashes(htmlspecialchars(stripslashes(get_option('yarpp_before_title')))).stripslashes(htmlspecialchars(stripslashes("<a href='PERMALINK$i'>RELATED TITLE $i</a>"))).(get_option('yarpp_show_excerpt')?"\r\t".stripslashes(htmlspecialchars(stripslashes(get_option('yarpp_before_post')))).yarpp_excerpt(LOREMIPSUM,get_option('yarpp_excerpt_length')).stripslashes(htmlspecialchars(stripslashes(get_option('yarpp_before_post')))):'').stripslashes(htmlspecialchars(stripslashes(get_option('yarpp_after_title'))))."
|
214 |
+
";
|
215 |
+
}
|
216 |
+
$democode .= stripslashes(htmlspecialchars(stripslashes(get_option('yarpp_after_related'))));
|
217 |
+
if (get_option('yarpp_promote_yarpp'))
|
218 |
+
$democode .= htmlspecialchars("\n<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>");
|
219 |
+
|
220 |
+
checkbox('auto_display',"Automatically display related posts? <a href='#' class='info'>more><span>This option automatically displays related posts right after the content on single entry pages. If this option is off, you will need to manually insert <code>related_posts()</code> or variants (<code>related_pagaes()</code> and <code>related_entries()</code>) into your theme files.","<tr valign='top'>
|
221 |
+
<th class='th-full' colspan='2' scope='row'>",'','<td rowspan="12" style="border-left:8px white solid;"><b>Display code example</b><br /><small>(Update options to reload.)</small><br/>'
|
222 |
+
."<code><pre style='overflow:auto;width:350px;'>".($democode)."</pre></code></td>"); ?>
|
223 |
+
<tr valign='top'>
|
224 |
+
<th>Before / after related entries:</th>
|
225 |
+
<td><input name="before_related" type="text" id="before_related" value="<?php echo stripslashes(htmlspecialchars(stripslashes(get_option('yarpp_before_related')))); ?>" size="10" /> / <input name="after_related" type="text" id="after_related" value="<?php echo stripslashes(htmlspecialchars(stripslashes(get_option('yarpp_after_related')))); ?>" size="10" /><em><small> For example: <ol></ol> or <div></div></small></em>
|
226 |
+
</td>
|
227 |
+
</tr>
|
228 |
+
<tr valign='top'>
|
229 |
+
<th>Before / after each post:</th>
|
230 |
+
<td><input name="before_title" type="text" id="before_title" value="<?php echo stripslashes(htmlspecialchars(stripslashes(get_option('yarpp_before_title')))); ?>" size="10" /> / <input name="after_title" type="text" id="after_title" value="<?php echo stripslashes(htmlspecialchars(stripslashes(get_option('yarpp_after_title')))); ?>" size="10" /><em><small> For example: <li></li> or <dl></dl></small></em>
|
231 |
+
</td>
|
232 |
+
</tr>
|
233 |
+
<?php checkbox('show_excerpt',"Show excerpt?","<tr valign='top'><th colspan='2'>",' name="show_excerpt" onclick="javascript:excerpt()"'); ?>
|
234 |
+
<?php textbox('excerpt_length','Excerpt length (No. of words):',null,"<tr name='excerpted' valign='top' ".(get_option('yarpp_show_excerpt')?'':"style='display:none'").">
|
235 |
+
<th>")?>
|
236 |
+
|
237 |
+
<tr name="excerpted" valign='top' <?php echo (get_option('yarpp_show_excerpt')?'':"style='display:none'")?>>
|
238 |
+
<th>Before / after (Excerpt):</th>
|
239 |
+
<td><input name="before_post" type="text" id="before_post" value="<?php echo stripslashes(htmlspecialchars(stripslashes(get_option('yarpp_before_post')))); ?>" size="10" /> / <input name="after_post" type="text" id="after_post" value="<?php echo stripslashes(htmlspecialchars(stripslashes(get_option('yarpp_after_post')))); ?>" size="10" /><em><small> For example: <li></li> or <dl></dl></small></em>
|
240 |
+
</td>
|
241 |
+
</tr>
|
242 |
+
|
243 |
+
<tr name="excerpted" valign='top'>
|
244 |
+
<th>Order results:</th>
|
245 |
+
<td><select name="order" id="name">
|
246 |
+
<option value="score DESC" <?php echo (get_option('yarpp_order')=='score DESC'?' selected="selected"':'')?>>score (high relevance to low)</option>
|
247 |
+
<option value="score ASC" <?php echo (get_option('yarpp_order')=='score ASC'?' selected="selected"':'')?>>score (low relevance to high)</option>
|
248 |
+
<option value="post_date DESC" <?php echo (get_option('yarpp_order')=='post_date DESC'?' selected="selected"':'')?>>date (new to old)</option>
|
249 |
+
<option value="post_date ASC" <?php echo (get_option('yarpp_order')=='post_date ASC'?' selected="selected"':'')?>>date (old to new)</option>
|
250 |
+
<option value="post_title ASC" <?php echo (get_option('yarpp_order')=='post_title ASC'?' selected="selected"':'')?>>title (alphabetical)</option>
|
251 |
+
<option value="post_title DESC" <?php echo (get_option('yarpp_order')=='post_title DESC'?' selected="selected"':'')?>>title (reverse alphabetical)</option>
|
252 |
+
</select>
|
253 |
+
</td>
|
254 |
+
</tr>
|
255 |
+
|
256 |
+
<?php textbox('no_results','Default display if no results:','40')?>
|
257 |
+
<?php checkbox('show_past_post',"Show password protected posts?"); ?>
|
258 |
+
<?php checkbox('past_only',"Show only previous posts?"); ?>
|
259 |
+
<?php checkbox('show_score',"Show admins (user level > 8) the match scores? <a href='#' class='info'>more><span>With this option on, each related entry's total 'match score' (all above the threshold, set above) are displayed after each entry title, <em>if you are an administrator and logged in.</em> Even if you see these values, your visitors will not.</span></a>"); ?>
|
260 |
+
<?php checkbox('promote_yarpp',"Help promote Yet Another Related Posts Plugin? <a href='#' class='info'>more><span>This option will add the code <code><p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p></code>. Try turning it on, updating your options, and see the code in the code example to the right. These links and donations are greatly appreciated.</span></a>"); ?>
|
261 |
+
</table>
|
262 |
+
|
263 |
+
<div>
|
264 |
+
<p class="submit">
|
265 |
+
<input type="submit" name="update_yarpp" value="Update options" />
|
266 |
+
<input type="submit" onclick='return confirm("Do you really want to reset your configuration?");' class="yarpp_warning" name="reset_yarpp" value="Reset options" />
|
267 |
+
</p>
|
268 |
+
</div>
|
269 |
+
</form>
|
270 |
+
|
271 |
<?php
|
272 |
|
273 |
// End Related Posts Options
|
readme.txt
CHANGED
@@ -5,57 +5,60 @@ Author URI: http://mitcho.com/
|
|
5 |
Plugin URI: http://mitcho.com/code/yarpp/
|
6 |
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=mitcho%40mitcho%2ecom&item_name=mitcho%2ecom%2fcode%3a%20donate%20to%20Michael%20Yoshitaka%20Erlewine&no_shipping=0&no_note=1&tax=0¤cy_code=USD&lc=US&bn=PP%2dDonationsBF&charset=UTF%2d8
|
7 |
Tags: related, posts, post, pages, page
|
8 |
-
Requires at least: 2.
|
9 |
-
Tested up to: 2.
|
10 |
-
Stable tag:
|
11 |
|
12 |
-
Returns a list of the related entries based on keyword matches, limited by a certain relatedness threshold.
|
13 |
|
14 |
-
|
15 |
|
16 |
-
Yet Another Related Posts Plugin (YARPP) gives you a list of posts and/or pages related to the current entry, introducing the reader to other relevant content on your site.
|
17 |
|
18 |
1. *Limiting by a threshold*: Peter Bowyer did the great work of making the algorithm use MySQL's [fulltext search](dev.mysql.com/doc/en/Fulltext_Search.html) score to identify related posts. But it just displayed, for example, the top 5 most "relevant" entries, even if some of them weren't at all relevant. Now you can set a threshold limit for relevance, and you get more related posts if there are more related posts and less if there are less. Ha!
|
19 |
-
2. *
|
20 |
-
3. *
|
21 |
-
4. *
|
|
|
|
|
22 |
|
23 |
-
|
24 |
|
25 |
-
|
26 |
|
27 |
-
|
28 |
|
29 |
-
|
30 |
|
31 |
If you would like to put the related posts display in another part of your theme, or display them in pages other than single entry pages, turn off "auto display" in the YARPP Options, then drop `related_posts()`, `related_pages()`, or `related_entries()` (see below) in your [WP loop](http://codex.wordpress.org/The_Loop). Change any options in the Related Posts (YARPP) Options pane in Admin > Plugins. See Examples in Other Notes for sample code you can drop into your theme.
|
32 |
|
33 |
There're also `related_posts_exist()`, `related_pages_exist()`, and `related_entries_exist()` functions, which return a boolean as expected.
|
34 |
|
35 |
-
|
36 |
|
37 |
By default, `related_posts()` gives you back posts only, `related_pages()` gives you pages, and there's `related_entries()` gives you posts and pages. When the "cross-relate posts and pages" option is checked in the YARPP options panel, `related_posts()`, `related_pages()`, and `related_entries()` will give you exactly the same output.
|
38 |
|
39 |
-
|
40 |
|
41 |
-
|
|
|
|
|
42 |
|
43 |
Most likely you have "no related posts" right now as the default "match threshold" is too high. Here's what I recommend to find an appropriate match threshold: first, lower your match threshold in the YARPP prefs to something ridiculously low, like 1 or 0.5. Make sure the last option "show admins the match scores" is on. Most likely the really low threshold will pull up many posts that aren't actually related (false positives), so look at some of your posts' related posts and their match scores. This will help you find an appropriate threshold. You want it lower than what you have now, but high enough so it doesn't have many false positives.
|
44 |
|
45 |
-
|
46 |
|
47 |
-
|
48 |
|
49 |
-
|
50 |
|
51 |
-
|
52 |
|
53 |
-
|
54 |
|
55 |
-
|
56 |
-
2. Um, something else! Let me know if you have any suggestions for improvement. ^^
|
57 |
|
58 |
-
|
59 |
|
60 |
* 1.0
|
61 |
* Initial upload
|
@@ -69,4 +72,32 @@ I highly recommend you disactivate YARPP, replace it with the new one, and then
|
|
69 |
* code and variable cleanup
|
70 |
* FAQ in the documentation
|
71 |
* 1.5.1
|
72 |
-
* Bugfix: standardized directory references to `yet-another-related-posts-plugin`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
Plugin URI: http://mitcho.com/code/yarpp/
|
6 |
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=mitcho%40mitcho%2ecom&item_name=mitcho%2ecom%2fcode%3a%20donate%20to%20Michael%20Yoshitaka%20Erlewine&no_shipping=0&no_note=1&tax=0¤cy_code=USD&lc=US&bn=PP%2dDonationsBF&charset=UTF%2d8
|
7 |
Tags: related, posts, post, pages, page
|
8 |
+
Requires at least: 2.3
|
9 |
+
Tested up to: 2.5.1
|
10 |
+
Stable tag: 2.0.2
|
11 |
|
12 |
+
Returns a list of the related entries based on keyword matches, limited by a certain relatedness threshold. New and improved, version 2.0!
|
13 |
|
14 |
+
== Description ==
|
15 |
|
16 |
+
Yet Another Related Posts Plugin (YARPP) gives you a list of posts and/or pages related to the current entry, introducing the reader to other relevant content on your site. Key features include:
|
17 |
|
18 |
1. *Limiting by a threshold*: Peter Bowyer did the great work of making the algorithm use MySQL's [fulltext search](dev.mysql.com/doc/en/Fulltext_Search.html) score to identify related posts. But it just displayed, for example, the top 5 most "relevant" entries, even if some of them weren't at all relevant. Now you can set a threshold limit for relevance, and you get more related posts if there are more related posts and less if there are less. Ha!
|
19 |
+
2. *Using tags and categories*: **New in 2.0!** The new 2.0 algorithm uses tags and categories. The new options screen puts you in control of how these factors should be used.
|
20 |
+
3. *Disallowing certain tags or categories*: **New in 2.0!** You can choose certain tags or categories as disallowed, meaning any page or post with such tags or categories will not be served up by the plugin.
|
21 |
+
4. *Related posts and pages*: **New in 1.1!** Puts you in control of pulling up related posts, pages, or both.
|
22 |
+
5. *Simple installation*: **New in 1.5!** Automatically displays related posts after content on single entry pages without any theme tinkering.
|
23 |
+
6. *Miscellany*: a nicer options screen (including a sample display of the code that is produced **New in 2.0**), displaying the fulltext match score on output for admins, an option to allow related posts from the future, a couple bug fixes, etc.
|
24 |
|
25 |
+
== Installation ==
|
26 |
|
27 |
+
= Auto display =
|
28 |
|
29 |
+
Since YARPP 1.5, you can just put the `yet-another-related-posts-plugin` directory in your `/wp-content/plugins/` directory, activate the plugin, and you're set! You'll see related posts in single entry (permalink) pages. If all your pages say "no related posts," see the FAQ.
|
30 |
|
31 |
+
= Manual installation =
|
32 |
|
33 |
If you would like to put the related posts display in another part of your theme, or display them in pages other than single entry pages, turn off "auto display" in the YARPP Options, then drop `related_posts()`, `related_pages()`, or `related_entries()` (see below) in your [WP loop](http://codex.wordpress.org/The_Loop). Change any options in the Related Posts (YARPP) Options pane in Admin > Plugins. See Examples in Other Notes for sample code you can drop into your theme.
|
34 |
|
35 |
There're also `related_posts_exist()`, `related_pages_exist()`, and `related_entries_exist()` functions, which return a boolean as expected.
|
36 |
|
37 |
+
= The "related" functions =
|
38 |
|
39 |
By default, `related_posts()` gives you back posts only, `related_pages()` gives you pages, and there's `related_entries()` gives you posts and pages. When the "cross-relate posts and pages" option is checked in the YARPP options panel, `related_posts()`, `related_pages()`, and `related_entries()` will give you exactly the same output.
|
40 |
|
41 |
+
== Frequently Asked Questions ==
|
42 |
|
43 |
+
If your question isn't here, ask your own question at [the Wordpress.org forums](http://wordpress.org/tags/yet-another-related-posts-plugin).
|
44 |
+
|
45 |
+
= Every page just says "no related posts"! What's up with that? =
|
46 |
|
47 |
Most likely you have "no related posts" right now as the default "match threshold" is too high. Here's what I recommend to find an appropriate match threshold: first, lower your match threshold in the YARPP prefs to something ridiculously low, like 1 or 0.5. Make sure the last option "show admins the match scores" is on. Most likely the really low threshold will pull up many posts that aren't actually related (false positives), so look at some of your posts' related posts and their match scores. This will help you find an appropriate threshold. You want it lower than what you have now, but high enough so it doesn't have many false positives.
|
48 |
|
49 |
+
= A weird number is displayed after each related post. What is this? =
|
50 |
|
51 |
+
This is the match score for each of those entries, relative to the current entry. Don't worry, though--this is just being displayed because the "show admins the match scores" option is on (as it is by default) and only blog admins can see those scores. Your readers will not see these values. See above for how to use these values.
|
52 |
|
53 |
+
= XXX plugin stopped working after I installed YARPP! =
|
54 |
|
55 |
+
Please submit such bugs by starting a new thread on [the Wordpress.org forums](http://wordpress.org/tags/yet-another-related-posts-plugin). I check the forums regularly and will try to release a quick bugfix.
|
56 |
|
57 |
+
= Things are weird after I upgraded. Ack! =
|
58 |
|
59 |
+
I highly recommend you disactivate YARPP, replace it with the new one, and then reactivate it.
|
|
|
60 |
|
61 |
+
== Version log ==
|
62 |
|
63 |
* 1.0
|
64 |
* Initial upload
|
72 |
* code and variable cleanup
|
73 |
* FAQ in the documentation
|
74 |
* 1.5.1
|
75 |
+
* Bugfix: standardized directory references to `yet-another-related-posts-plugin`
|
76 |
+
* 2.0
|
77 |
+
* New algorithm which considers tags and categories, by frequent request
|
78 |
+
* Order by score, date, or title, [by request](http://wordpress.org/support/topic/158459)
|
79 |
+
* Excluding certain tags or categories, [by request](http://wordpress.org/support/topic/161263)
|
80 |
+
* Sample output displayed in the options screen
|
81 |
+
* Bugfix: [an excerpt length bug](http://wordpress.org/support/topic/155034?replies=5)
|
82 |
+
* Bugfix: now compatible with the following plugins:
|
83 |
+
- diggZEt
|
84 |
+
- WP-Syntax
|
85 |
+
- Viper's Video Quicktags
|
86 |
+
- WP-CodeBox
|
87 |
+
- WP shortcodes
|
88 |
+
* 2.0.1
|
89 |
+
* Bugfix: [`admin_menu` instead of `admin_head`](http://konstruktors.com/blog/wordpress/277-fixing-postpost-and-ozh-absolute-comments-plugins/)
|
90 |
+
* Bugfix: [a variable scope issue](http://wordpress.org/support/topic/188550) crucial for 2.0 upgrading
|
91 |
+
* 2.0.2
|
92 |
+
* Versioning bugfix (rerelease of 2.0.1)
|
93 |
+
|
94 |
+
|
95 |
+
== Future versions ==
|
96 |
+
|
97 |
+
The following feature requests have been made and may be incorporated into a future release. If you have a bug fix, please start a new thread on [the Wordpress.org forums](http://wordpress.org/tags/yet-another-related-posts-plugin).
|
98 |
+
|
99 |
+
* User-defineable stopwords, especially to support other languages, [by request](http://wordpress.org/support/topic/159359)
|
100 |
+
* Widgetization, [by request](http://wordpress.org/support/topic/160459)
|
101 |
+
* Date and comment count in excerpt, [by request](http://wordpress.org/support/topic/156231)
|
102 |
+
* RSS feed support: an option to automagically show related posts in RSS feeds, [by request](http://wordpress.org/support/topic/151766).
|
103 |
+
* Sentece-aware excerpts, [by request](http://wordpress.org/support/topic/162465)
|
yarpp.php
CHANGED
@@ -2,8 +2,8 @@
|
|
2 |
/*
|
3 |
Plugin Name: Yet Another Related Posts Plugin
|
4 |
Plugin URI: http://mitcho.com/code/yarpp/
|
5 |
-
Description: Returns a list of the related entries based on keyword matches, limited by a certain relatedness threshold.
|
6 |
-
Version:
|
7 |
Author: mitcho (Michael Yoshitaka Erlewine)
|
8 |
*/
|
9 |
|
@@ -11,9 +11,12 @@ require_once('includes.php');
|
|
11 |
require_once('magic.php');
|
12 |
require_once('related-functions.php');
|
13 |
|
14 |
-
add_action('
|
15 |
add_action('admin_print_scripts','yarpp_upgrade_check');
|
16 |
-
add_filter('the_content','yarpp_default');
|
17 |
register_activation_hook(__FILE__,'yarpp_activate');
|
18 |
|
|
|
|
|
|
|
19 |
?>
|
2 |
/*
|
3 |
Plugin Name: Yet Another Related Posts Plugin
|
4 |
Plugin URI: http://mitcho.com/code/yarpp/
|
5 |
+
Description: Returns a list of the related entries based on keyword matches, limited by a certain relatedness threshold. New and improved, version 2.0!
|
6 |
+
Version: 2.0.2
|
7 |
Author: mitcho (Michael Yoshitaka Erlewine)
|
8 |
*/
|
9 |
|
11 |
require_once('magic.php');
|
12 |
require_once('related-functions.php');
|
13 |
|
14 |
+
add_action('admin_menu','yarpp_admin_menu');
|
15 |
add_action('admin_print_scripts','yarpp_upgrade_check');
|
16 |
+
add_filter('the_content','yarpp_default',1200);
|
17 |
register_activation_hook(__FILE__,'yarpp_activate');
|
18 |
|
19 |
+
// new in 2.0: add as a widget
|
20 |
+
add_action('plugins_loaded', 'widget_yarpp_init');
|
21 |
+
|
22 |
?>
|