Version Description
Download this release
Release Info
Developer | mitchoyoshitaka |
Plugin | Yet Another Related Posts Plugin (YARPP) |
Version | 2.1 |
Comparing to | |
See all releases |
Code changes from version 2.0.6 to 2.1
- includes.php +60 -16
- magic.php +149 -58
- options.php +161 -39
- readme.txt +87 -14
- related-functions.php +8 -12
- yarpp.php +4 -2
includes.php
CHANGED
@@ -11,21 +11,34 @@ $yarpp_value_options = array('threshold' => 5,
|
|
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 |
-
'
|
|
|
|
|
|
|
29 |
|
30 |
function yarpp_enabled() {
|
31 |
global $wpdb;
|
@@ -68,11 +81,20 @@ function yarpp_activate() {
|
|
68 |
return 0;
|
69 |
}
|
70 |
}
|
71 |
-
add_option('yarpp_version','2.
|
72 |
-
update_option('yarpp_version','2.
|
73 |
return 1;
|
74 |
}
|
75 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
76 |
function yarpp_upgrade_check($inuse = false) {
|
77 |
global $wpdb, $yarpp_value_options, $yarpp_binary_options;
|
78 |
|
@@ -85,6 +107,8 @@ function yarpp_upgrade_check($inuse = false) {
|
|
85 |
add_option("yarpp_$option",$yarpp_binary_options[$option]." ");
|
86 |
}
|
87 |
|
|
|
|
|
88 |
if (get_option('threshold') and get_option('limit') and get_option('len')) {
|
89 |
yarpp_activate();
|
90 |
yarpp_upgrade_one_five();
|
@@ -111,8 +135,8 @@ function yarpp_upgrade_check($inuse = false) {
|
|
111 |
$wpdb->query("ALTER TABLE $wpdb->posts ADD FULLTEXT `yarpp_content` ( `post_content`)"); update_option('yarpp_version','2.03');
|
112 |
}
|
113 |
|
114 |
-
if (get_option('yarpp_version') < 2.
|
115 |
-
update_option('yarpp_version','2.
|
116 |
}
|
117 |
|
118 |
// just in case, try to add the index one more time.
|
@@ -140,7 +164,7 @@ function widget_yarpp_init() {
|
|
140 |
|
141 |
function widget_yarpp($args) {
|
142 |
extract($args);
|
143 |
-
global $wpdb, $post
|
144 |
if (is_single()) {
|
145 |
echo $before_widget;
|
146 |
echo $before_title . 'Related Posts' . $after_title;
|
@@ -152,25 +176,45 @@ function widget_yarpp_init() {
|
|
152 |
}
|
153 |
|
154 |
function yarpp_default($content) {
|
155 |
-
global $wpdb, $post
|
156 |
-
if (
|
157 |
-
return $content
|
158 |
-
|
|
|
|
|
159 |
return $content;
|
160 |
-
}
|
161 |
}
|
162 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
163 |
/* new in 2.0! apply_filters_if_white (previously apply_filters_without) now has a blacklist. It's defined here. */
|
164 |
|
165 |
/* blacklisted so far:
|
166 |
-
-
|
|
|
|
|
167 |
- WP-Syntax
|
168 |
- Viper's Video Quicktags
|
169 |
- WP-CodeBox
|
170 |
- WP shortcodes
|
171 |
*/
|
172 |
|
173 |
-
$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');
|
174 |
$yarpp_blackmethods = array(null,'addinlinejs','replacebbcode');
|
175 |
|
176 |
function yarpp_white($filter) {
|
11 |
'before_related' => '<p>Related posts:<ol>',
|
12 |
'after_related' => '</ol></p>',
|
13 |
'no_results' => '<p>No related posts.</p>',
|
14 |
+
'order' => 'score DESC',
|
15 |
+
'rss_limit' => 3,
|
16 |
+
'rss_excerpt_length' => 10,
|
17 |
+
'rss_before_title' => '<li>',
|
18 |
+
'rss_after_title' => '</li>',
|
19 |
+
'rss_before_post' => ' <small>',
|
20 |
+
'rss_after_post' => '</small>',
|
21 |
+
'rss_before_related' => '<p>Related posts:<ol>',
|
22 |
+
'rss_after_related' => '</ol></p>',
|
23 |
+
'rss_no_results' => '<p>No related posts.</p>',
|
24 |
+
'rss_order' => 'score DESC',
|
25 |
'title' => '2',
|
26 |
'body' => '2',
|
27 |
'categories' => '2',
|
28 |
'tags' => '2',
|
29 |
'distags' => '',
|
30 |
+
'discats' => '');
|
|
|
|
|
31 |
$yarpp_binary_options = array('past_only' => true,
|
32 |
'show_score' => true,
|
33 |
'show_excerpt' => false,
|
34 |
+
'rss_show_excerpt' => false,
|
35 |
'show_pass_post' => false,
|
36 |
'cross_relate' => false,
|
37 |
'auto_display' => true,
|
38 |
+
'rss_display' => true,
|
39 |
+
'rss_excerpt_display' => true,
|
40 |
+
'promote_yarpp' => false,
|
41 |
+
'rss_promote_yarpp' => false);
|
42 |
|
43 |
function yarpp_enabled() {
|
44 |
global $wpdb;
|
81 |
return 0;
|
82 |
}
|
83 |
}
|
84 |
+
add_option('yarpp_version','2.1');
|
85 |
+
update_option('yarpp_version','2.1');
|
86 |
return 1;
|
87 |
}
|
88 |
|
89 |
+
function yarpp_myisam_check() {
|
90 |
+
global $wpdb;
|
91 |
+
$tables = $wpdb->get_results("show table status like '$wpdb->posts'");
|
92 |
+
foreach ($tables as $table) {
|
93 |
+
if ($table->Engine == 'MyISAM') return 1;
|
94 |
+
}
|
95 |
+
return 0;
|
96 |
+
}
|
97 |
+
|
98 |
function yarpp_upgrade_check($inuse = false) {
|
99 |
global $wpdb, $yarpp_value_options, $yarpp_binary_options;
|
100 |
|
107 |
add_option("yarpp_$option",$yarpp_binary_options[$option]." ");
|
108 |
}
|
109 |
|
110 |
+
// upgrade check
|
111 |
+
|
112 |
if (get_option('threshold') and get_option('limit') and get_option('len')) {
|
113 |
yarpp_activate();
|
114 |
yarpp_upgrade_one_five();
|
135 |
$wpdb->query("ALTER TABLE $wpdb->posts ADD FULLTEXT `yarpp_content` ( `post_content`)"); update_option('yarpp_version','2.03');
|
136 |
}
|
137 |
|
138 |
+
if (get_option('yarpp_version') < 2.1) {
|
139 |
+
update_option('yarpp_version','2.1');
|
140 |
}
|
141 |
|
142 |
// just in case, try to add the index one more time.
|
164 |
|
165 |
function widget_yarpp($args) {
|
166 |
extract($args);
|
167 |
+
global $wpdb, $post;
|
168 |
if (is_single()) {
|
169 |
echo $before_widget;
|
170 |
echo $before_title . 'Related Posts' . $after_title;
|
176 |
}
|
177 |
|
178 |
function yarpp_default($content) {
|
179 |
+
global $wpdb, $post;
|
180 |
+
if (is_feed())
|
181 |
+
return yarpp_rss($content);
|
182 |
+
elseif (yarpp_get_option('auto_display') and is_single())
|
183 |
+
return $content.yarpp_related(array('post'),array(),false,'website');
|
184 |
+
else
|
185 |
return $content;
|
|
|
186 |
}
|
187 |
|
188 |
+
function yarpp_rss($content) {
|
189 |
+
global $wpdb, $post;
|
190 |
+
if (yarpp_get_option('rss_display'))
|
191 |
+
return $content.yarpp_related(array('post'),array(),false,'rss');
|
192 |
+
else
|
193 |
+
return $content;
|
194 |
+
}
|
195 |
+
|
196 |
+
function yarpp_rss_excerpt($content) {
|
197 |
+
global $wpdb, $post;
|
198 |
+
if (yarpp_get_option('rss_excerpt_display'))
|
199 |
+
return $content.clean_pre(yarpp_related(array('post'),array(),false,'rss'));
|
200 |
+
else
|
201 |
+
return $content;
|
202 |
+
}
|
203 |
+
|
204 |
+
|
205 |
/* new in 2.0! apply_filters_if_white (previously apply_filters_without) now has a blacklist. It's defined here. */
|
206 |
|
207 |
/* blacklisted so far:
|
208 |
+
- diggZ-Et
|
209 |
+
- reddZ-Et
|
210 |
+
- dzoneZ-Et
|
211 |
- WP-Syntax
|
212 |
- Viper's Video Quicktags
|
213 |
- WP-CodeBox
|
214 |
- WP shortcodes
|
215 |
*/
|
216 |
|
217 |
+
$yarpp_blacklist = array(null,'yarpp_default','diggZEt_AddBut','reddZEt_AddBut','dzoneZEt_AddBut','wp_syntax_before_filter','wp_syntax_after_filter','wp_codebox_before_filter','wp_codebox_after_filter','do_shortcode');
|
218 |
$yarpp_blackmethods = array(null,'addinlinejs','replacebbcode');
|
219 |
|
220 |
function yarpp_white($filter) {
|
magic.php
CHANGED
@@ -57,13 +57,42 @@ function post_body_keywords($num_to_ret = 20) {
|
|
57 |
|
58 |
}
|
59 |
|
60 |
-
function yarpp_sql($
|
61 |
global $wpdb, $post;
|
62 |
|
63 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
|
65 |
// if cross_relate is set, override the type argument and make sure both matches are accepted in the sql query
|
66 |
-
if (
|
67 |
|
68 |
// Fetch keywords
|
69 |
$body_terms = post_body_keywords();
|
@@ -75,10 +104,15 @@ function yarpp_sql($options_array,$giveresults = true) {
|
|
75 |
|
76 |
// get weights
|
77 |
|
78 |
-
$bodyweight = ((
|
79 |
-
$titleweight = ((
|
80 |
-
$tagweight = ((
|
81 |
-
$catweight = ((
|
|
|
|
|
|
|
|
|
|
|
82 |
|
83 |
$totalweight = $bodyweight + $titleweight + $tagweight + $catweight;
|
84 |
|
@@ -86,70 +120,125 @@ function yarpp_sql($options_array,$giveresults = true) {
|
|
86 |
|
87 |
// get disallowed categories and tags
|
88 |
|
89 |
-
$disterms = implode(',', array_filter(array_merge(explode(','
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
90 |
|
91 |
-
|
92 |
-
|
|
|
|
|
93 |
|
94 |
-
|
95 |
-
|
96 |
-
|
|
|
|
|
|
|
97 |
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
|
|
103 |
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
left JOIN $wpdb->term_taxonomy AS cattax ON ( catrel.term_taxonomy_id = cattax.term_taxonomy_id
|
108 |
-
AND cattax.taxonomy = 'category')
|
109 |
|
110 |
-
|
|
|
|
|
|
|
111 |
|
112 |
-
$newsql .=
|
113 |
-
$newsql .= ((!$show_pass_post)?" and post_password ='' ":' ');
|
114 |
-
$newsql .= " and post_type IN ('".implode("', '",$type)."')";
|
115 |
|
116 |
-
|
117 |
-
$newsql .= "
|
118 |
-
|
|
|
|
|
|
|
119 |
|
120 |
-
$newsql .= ((
|
121 |
-
$newsql .= ((
|
122 |
-
$newsql .= ((
|
123 |
-
$newsql .= ((
|
124 |
-
$newsql .= " order by ".((
|
125 |
|
126 |
if (!$giveresults) {
|
127 |
-
$
|
128 |
}
|
129 |
|
|
|
130 |
return $newsql;
|
131 |
}
|
132 |
|
133 |
-
|
|
|
|
|
134 |
global $wpdb, $post, $userdata;
|
135 |
get_currentuserinfo();
|
136 |
|
|
|
|
|
|
|
|
|
|
|
|
|
137 |
// get options
|
138 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
139 |
$optvals = array();
|
140 |
-
foreach (array_keys($options) as $
|
141 |
-
if (isset($args[$
|
142 |
-
$optvals[$
|
143 |
} else {
|
144 |
-
$optvals[$
|
145 |
}
|
146 |
}
|
147 |
extract($optvals);
|
148 |
-
$optvals['type'] = $type;
|
149 |
-
|
150 |
-
// Primary SQL query
|
151 |
|
152 |
-
$results = $wpdb->get_results(yarpp_sql($
|
153 |
$output = '';
|
154 |
if ($results) {
|
155 |
foreach ($results as $result) {
|
@@ -157,38 +246,40 @@ function yarpp_related($type,$args,$echo = true) {
|
|
157 |
$permalink = get_permalink($result->ID);
|
158 |
$post_content = strip_tags($result->post_content);
|
159 |
$post_content = stripslashes($post_content);
|
160 |
-
$output .= "$before_title<a href='$permalink' rel='bookmark' title='Permanent Link: $title'>$title"
|
|
|
|
|
|
|
161 |
if ($show_excerpt) {
|
162 |
$output .= $before_post . yarpp_excerpt($post_content,$excerpt_length) . $after_post;
|
163 |
}
|
164 |
$output .= $after_title;
|
165 |
}
|
166 |
-
$output = stripslashes(stripslashes(
|
167 |
-
if (
|
168 |
$output .= "\n<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>";
|
169 |
|
170 |
} else {
|
171 |
-
$output =
|
172 |
}
|
173 |
-
if ($echo) echo $output; else return $output;
|
174 |
}
|
175 |
|
176 |
function yarpp_related_exist($type,$args) {
|
177 |
global $wpdb, $post;
|
178 |
|
179 |
-
$options = array('threshold','show_pass_post','past_only');
|
180 |
$optvals = array();
|
181 |
-
foreach (array_keys($options) as $
|
182 |
-
if (isset($args[$
|
183 |
-
$optvals[$
|
184 |
} else {
|
185 |
-
$optvals[$
|
186 |
}
|
187 |
}
|
188 |
extract($optvals);
|
189 |
-
$optvals['type'] = $type;
|
190 |
|
191 |
-
$result = $wpdb->get_var(yarpp_sql($
|
192 |
return $result > 0 ? true: false;
|
193 |
}
|
194 |
|
57 |
|
58 |
}
|
59 |
|
60 |
+
function yarpp_sql($type,$args,$giveresults = true,$domain='website') {
|
61 |
global $wpdb, $post;
|
62 |
|
63 |
+
// set the "domain prefix", used for all the preferences.
|
64 |
+
if ($domain == 'rss')
|
65 |
+
$domainprefix = 'rss_';
|
66 |
+
else
|
67 |
+
$domainprefix = '';
|
68 |
+
|
69 |
+
$options = array('limit'=>"${domainprefix}limit",
|
70 |
+
'order'=>"${domainprefix}order",
|
71 |
+
'threshold'=>'threshold',
|
72 |
+
'show_excerpt'=>"${domainprefix}show_excerpt",
|
73 |
+
'excerpt_length'=>"${domainprefix}excerpt_length",
|
74 |
+
'show_pass_post'=>'show_pass_post',
|
75 |
+
'past_only'=>'past_only',
|
76 |
+
'cross_relate'=>'cross_relate',
|
77 |
+
'body'=>'body',
|
78 |
+
'title'=>'title',
|
79 |
+
'tags'=>'tags',
|
80 |
+
'categories'=>'categories',
|
81 |
+
'distags'=>'distags',
|
82 |
+
'discats'=>'discats');
|
83 |
+
$optvals = array();
|
84 |
+
foreach (array_keys($options) as $option) {
|
85 |
+
if (isset($args[$option])) {
|
86 |
+
$optvals[$option] = stripslashes($args[$option]);
|
87 |
+
} else {
|
88 |
+
$optvals[$option] = stripslashes(stripslashes(yarpp_get_option($options[$option])));
|
89 |
+
}
|
90 |
+
}
|
91 |
+
|
92 |
+
extract($optvals);
|
93 |
|
94 |
// if cross_relate is set, override the type argument and make sure both matches are accepted in the sql query
|
95 |
+
if ($cross_relate) $type = array('post','page');
|
96 |
|
97 |
// Fetch keywords
|
98 |
$body_terms = post_body_keywords();
|
104 |
|
105 |
// get weights
|
106 |
|
107 |
+
$bodyweight = (($body == 3)?3:(($body == 2)?1:0));
|
108 |
+
$titleweight = (($title == 3)?3:(($title == 2)?1:0));
|
109 |
+
$tagweight = (($tags != 1)?1:0);
|
110 |
+
$catweight = (($categories != 1)?1:0);
|
111 |
+
$weights = array();
|
112 |
+
$weights['body'] = $bodyweight;
|
113 |
+
$weights['title'] = $titleweight;
|
114 |
+
$weights['cat'] = $catweight;
|
115 |
+
$weights['tag'] = $tagweight;
|
116 |
|
117 |
$totalweight = $bodyweight + $titleweight + $tagweight + $catweight;
|
118 |
|
120 |
|
121 |
// get disallowed categories and tags
|
122 |
|
123 |
+
$disterms = implode(',', array_filter(array_merge(explode(',',$discats),explode(',',$distags)),'is_numeric'));
|
124 |
+
|
125 |
+
$usedisterms = count(array_filter(array_merge(explode(',',$discats),explode(',',$distags)),'is_numeric'));
|
126 |
+
|
127 |
+
$criteria = array();
|
128 |
+
if ($bodyweight)
|
129 |
+
$criteria['body'] = "(MATCH (post_content) AGAINST ('".post_body_keywords()."'))";
|
130 |
+
if ($titleweight)
|
131 |
+
$criteria['title'] = "(MATCH (post_title) AGAINST ('".post_title_keywords()."'))";
|
132 |
+
if ($tagweight)
|
133 |
+
$criteria['tag'] = "COUNT( DISTINCT tagtax.term_taxonomy_id )";
|
134 |
+
if ($catweight)
|
135 |
+
$criteria['cat'] = "COUNT( DISTINCT cattax.term_taxonomy_id )";
|
136 |
+
|
137 |
+
$newsql = "SELECT ID, post_title, post_date, post_content, ";
|
138 |
+
|
139 |
+
foreach ($criteria as $key => $value) {
|
140 |
+
$newsql .= "$value as ${key}score, ";
|
141 |
+
}
|
142 |
+
|
143 |
+
$newsql .= '(0';
|
144 |
+
foreach ($criteria as $key => $value) {
|
145 |
+
$newsql .= "+ $value * ".$weights[$key];
|
146 |
+
}
|
147 |
+
$newsql .= ') as score';
|
148 |
+
|
149 |
+
if ($usedisterms)
|
150 |
+
$newsql .= ", count(blockterm.term_id) as block";
|
151 |
+
|
152 |
+
$newsql .= "\n from $wpdb->posts \n";
|
153 |
|
154 |
+
if ($usedisterms)
|
155 |
+
$newsql .= " left join $wpdb->term_relationships as blockrel on ($wpdb->posts.ID = blockrel.object_id)
|
156 |
+
left join $wpdb->term_taxonomy as blocktax using (`term_taxonomy_id`)
|
157 |
+
left join $wpdb->terms as blockterm on (blocktax.term_id = blockterm.term_id and blockterm.term_id in ($disterms))\n";
|
158 |
|
159 |
+
if ($tagweight)
|
160 |
+
$newsql .= " left JOIN $wpdb->term_relationships AS thistag ON (thistag.object_id = $post->ID )
|
161 |
+
left JOIN $wpdb->term_relationships AS tagrel on (tagrel.term_taxonomy_id = thistag.term_taxonomy_id
|
162 |
+
AND tagrel.object_id = $wpdb->posts.ID)
|
163 |
+
left JOIN $wpdb->term_taxonomy AS tagtax ON ( tagrel.term_taxonomy_id = tagtax.term_taxonomy_id
|
164 |
+
AND tagtax.taxonomy = 'post_tag')\n";
|
165 |
|
166 |
+
if ($catweight)
|
167 |
+
$newsql .= " left JOIN $wpdb->term_relationships AS thiscat ON (thiscat.object_id = $post->ID )
|
168 |
+
left JOIN $wpdb->term_relationships AS catrel on (catrel.term_taxonomy_id = thiscat.term_taxonomy_id
|
169 |
+
AND catrel.object_id = $wpdb->posts.ID)
|
170 |
+
left JOIN $wpdb->term_taxonomy AS cattax ON ( catrel.term_taxonomy_id = cattax.term_taxonomy_id
|
171 |
+
AND cattax.taxonomy = 'category')\n";
|
172 |
|
173 |
+
// WHERE
|
174 |
+
|
175 |
+
$newsql .= " where (post_status IN ( 'publish', 'static' ) and ID != '$post->ID')";
|
|
|
|
|
176 |
|
177 |
+
if ($past_only)
|
178 |
+
$newsql .= " and post_date <= '$now' ";
|
179 |
+
if (!$show_pass_post)
|
180 |
+
$newsql .= " and post_password ='' ";
|
181 |
|
182 |
+
$newsql .= " and post_type IN ('".implode("', '",$type)."')";
|
|
|
|
|
183 |
|
184 |
+
// GROUP BY
|
185 |
+
$newsql .= "\n group by id \n";
|
186 |
+
// HAVING
|
187 |
+
$newsql .= " having score >= $threshold";
|
188 |
+
if ($usedisterms)
|
189 |
+
$newsql .= " and block = 0";
|
190 |
|
191 |
+
$newsql .= (($categories == 3)?' and catscore >= 1':'');
|
192 |
+
$newsql .= (($categories == 4)?' and catscore >= 2':'');
|
193 |
+
$newsql .= (($tags == 3)?' and tagscore >= 1':'');
|
194 |
+
$newsql .= (($tags == 4)?' and tagscore >= 2':'');
|
195 |
+
$newsql .= " order by ".(($order?$order:"score desc"))." limit ".$limit;
|
196 |
|
197 |
if (!$giveresults) {
|
198 |
+
$newsql = "select count(t.ID) from ($newsql) as t";
|
199 |
}
|
200 |
|
201 |
+
//echo "<!--$newsql-->";
|
202 |
return $newsql;
|
203 |
}
|
204 |
|
205 |
+
/* new in 2.1! the domain argument refers to {website,widget,rss}, though widget is not used yet. */
|
206 |
+
|
207 |
+
function yarpp_related($type,$args,$echo = true,$domain = 'website') {
|
208 |
global $wpdb, $post, $userdata;
|
209 |
get_currentuserinfo();
|
210 |
|
211 |
+
// set the "domain prefix", used for all the preferences.
|
212 |
+
if ($domain == 'rss')
|
213 |
+
$domainprefix = 'rss_';
|
214 |
+
else
|
215 |
+
$domainprefix = '';
|
216 |
+
|
217 |
// get options
|
218 |
+
// note the 2.1 change... the options array changed from what you might call a "list" to a "hash"... this changes the structure of the $args to something which is, in the long term, much more useful
|
219 |
+
$options = array(
|
220 |
+
'before_related'=>"${domainprefix}before_related",
|
221 |
+
'after_related'=>"${domainprefix}after_related",
|
222 |
+
'before_title'=>"${domainprefix}before_title",
|
223 |
+
'after_title'=>"${domainprefix}after_title",
|
224 |
+
'show_excerpt'=>"${domainprefix}show_excerpt",
|
225 |
+
'excerpt_length'=>"${domainprefix}excerpt_length",
|
226 |
+
'before_post'=>"${domainprefix}before_post",
|
227 |
+
'after_post'=>"${domainprefix}after_post",
|
228 |
+
'no_results'=>"${domainprefix}no_results",
|
229 |
+
'promote_yarpp'=>"${domainprefix}promote_yarpp",
|
230 |
+
'show_score'=>'show_score');
|
231 |
$optvals = array();
|
232 |
+
foreach (array_keys($options) as $option) {
|
233 |
+
if (isset($args[$option])) {
|
234 |
+
$optvals[$option] = stripslashes($args[$option]);
|
235 |
} else {
|
236 |
+
$optvals[$option] = stripslashes(stripslashes(yarpp_get_option($options[$option])));
|
237 |
}
|
238 |
}
|
239 |
extract($optvals);
|
|
|
|
|
|
|
240 |
|
241 |
+
$results = $wpdb->get_results(yarpp_sql($type,$args,true,$domain));
|
242 |
$output = '';
|
243 |
if ($results) {
|
244 |
foreach ($results as $result) {
|
246 |
$permalink = get_permalink($result->ID);
|
247 |
$post_content = strip_tags($result->post_content);
|
248 |
$post_content = stripslashes($post_content);
|
249 |
+
$output .= "$before_title<a href='$permalink' rel='bookmark' title='Permanent Link: $title'>$title";
|
250 |
+
if ($show_score and $userdata->user_level >= 8 and $domain != 'rss')
|
251 |
+
$output .= ' <abbr title="'.round($result->score,3).' is the YARPP match score between the current entry and this related entry. You are seeing this value because you are logged in to WordPress as an administrator. It is not shown to regular visitors.">('.round($result->score,3).')</abbr>';
|
252 |
+
$output .= '</a>';
|
253 |
if ($show_excerpt) {
|
254 |
$output .= $before_post . yarpp_excerpt($post_content,$excerpt_length) . $after_post;
|
255 |
}
|
256 |
$output .= $after_title;
|
257 |
}
|
258 |
+
$output = stripslashes(stripslashes($before_related)).$output.stripslashes(stripslashes($after_related));
|
259 |
+
if ($promote_yarpp)
|
260 |
$output .= "\n<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>";
|
261 |
|
262 |
} else {
|
263 |
+
$output = $no_results;
|
264 |
}
|
265 |
+
if ($echo) echo $output; else return ((!empty($output))?"\n\n":'').$output;
|
266 |
}
|
267 |
|
268 |
function yarpp_related_exist($type,$args) {
|
269 |
global $wpdb, $post;
|
270 |
|
271 |
+
$options = array('threshold'=>'threshold','show_pass_post'=>'show_pass_post','past_only'=>'past_only');
|
272 |
$optvals = array();
|
273 |
+
foreach (array_keys($options) as $option) {
|
274 |
+
if (isset($args[$option])) {
|
275 |
+
$optvals[$option] = stripslashes($args[$option]);
|
276 |
} else {
|
277 |
+
$optvals[$option] = stripslashes(stripslashes(yarpp_get_option($options[$option])));
|
278 |
}
|
279 |
}
|
280 |
extract($optvals);
|
|
|
281 |
|
282 |
+
$result = $wpdb->get_var(yarpp_sql($type,$args,false,$domain));
|
283 |
return $result > 0 ? true: false;
|
284 |
}
|
285 |
|
options.php
CHANGED
@@ -1,11 +1,37 @@
|
|
1 |
<?php
|
2 |
// Begin Related Posts Options
|
3 |
|
4 |
-
global $wpdb, $yarpp_value_options, $yarpp_binary_options;
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
echo '</
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
}
|
10 |
|
11 |
yarpp_reinforce(); // just in case, set default options, etc.
|
@@ -30,6 +56,9 @@ if (isset($_POST['update_yarpp'])) {
|
|
30 |
foreach (array_keys($yarpp_value_options) as $option) {
|
31 |
yarpp_set_option($option,addslashes($_POST[$option]));
|
32 |
}
|
|
|
|
|
|
|
33 |
if (isset($_POST['discats'])) {
|
34 |
yarpp_set_option('discats',implode(',',array_keys($_POST['discats']))); // discats is different
|
35 |
} else {
|
@@ -102,14 +131,22 @@ function select($option,$desc,$type='word',$tr="<tr valign='top'>
|
|
102 |
|
103 |
?>
|
104 |
<script type="text/javascript">
|
105 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
106 |
|
107 |
var css=document.createElement("link");
|
108 |
css.setAttribute("rel", "stylesheet");
|
109 |
css.setAttribute("type", "text/css");
|
110 |
css.setAttribute("href", "../wp-content/plugins/yet-another-related-posts-plugin/options.css");
|
111 |
document.getElementsByTagName("head")[0].appendChild(css);
|
112 |
-
|
|
|
113 |
</script>
|
114 |
|
115 |
<div class="wrap">
|
@@ -135,14 +172,14 @@ document.getElementsByTagName("head")[0].appendChild(css);
|
|
135 |
<form method="post">
|
136 |
|
137 |
|
138 |
-
<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>
|
139 |
|
140 |
|
141 |
<!--The Pool-->
|
142 |
<h3>"The Pool"</h3>
|
143 |
<p>"The Pool" refers to the pool of posts and pages that are candidates for display as related to the current entry.</p>
|
144 |
|
145 |
-
<table class="form-table">
|
146 |
<tbody>
|
147 |
<tr valign='top'>
|
148 |
<th scope='row'>Disallow by category:</th><td><div style="overflow:auto;max-height:100px;">
|
@@ -150,10 +187,9 @@ document.getElementsByTagName("head")[0].appendChild(css);
|
|
150 |
$discats = explode(',',yarpp_get_option('discats'));
|
151 |
array_unshift($discats,' ');
|
152 |
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) {
|
153 |
-
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]'
|
154 |
}?>
|
155 |
-
</div></td>
|
156 |
-
</tr>
|
157 |
<tr valign='top'>
|
158 |
<th scope='row'>Disallow by tag: </th>
|
159 |
<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(yarpp_get_option($option))))));?>' size='40' />-->
|
@@ -161,10 +197,11 @@ document.getElementsByTagName("head")[0].appendChild(css);
|
|
161 |
$distags = explode(',',yarpp_get_option('distags'));
|
162 |
array_unshift($distags,' ');
|
163 |
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) {
|
164 |
-
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]'
|
165 |
}?>
|
166 |
-
</div></td>
|
167 |
-
|
|
|
168 |
</tbody>
|
169 |
</table>
|
170 |
|
@@ -172,9 +209,8 @@ document.getElementsByTagName("head")[0].appendChild(css);
|
|
172 |
<h3>"Relatedness" options</h3>
|
173 |
<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>
|
174 |
|
175 |
-
<table class="form-table">
|
176 |
<tbody>
|
177 |
-
<?php textbox('limit','Maximum number of related posts:')?>
|
178 |
|
179 |
<!-- <div id="mySlider"><span>do not consider</span>
|
180 |
<span>consider</span>
|
@@ -183,34 +219,59 @@ document.getElementsByTagName("head")[0].appendChild(css);
|
|
183 |
</div>-->
|
184 |
|
185 |
<?php textbox('threshold','Match threshold:')?>
|
186 |
-
<?php importance2('title',"Titles: "
|
187 |
-
|
188 |
-
<?php
|
189 |
-
|
|
|
|
|
|
|
|
|
190 |
<?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>"); ?>
|
191 |
</tbody>
|
192 |
</table>
|
193 |
|
194 |
<script language="javascript">
|
195 |
-
|
196 |
function excerpt() {
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
}
|
201 |
-
|
202 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
203 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
204 |
}
|
205 |
-
|
206 |
-
//]]!>
|
207 |
</script>
|
208 |
|
209 |
|
210 |
<!-- Display options -->
|
211 |
-
<h3>Display options</h3>
|
212 |
|
213 |
-
<table class="form-table">
|
214 |
<?php
|
215 |
// construct the demo code based on current preferences
|
216 |
|
@@ -224,20 +285,21 @@ $democode .= stripslashes(yarpp_get_option('after_related',true));
|
|
224 |
if (yarpp_get_option('promote_yarpp'))
|
225 |
$democode .= htmlspecialchars("\n<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>");
|
226 |
|
227 |
-
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
|
228 |
-
<th class='th-full' colspan='2' scope='row'>",'','<td rowspan="
|
229 |
."<code><pre style='overflow:auto;width:350px;'>".($democode)."</pre></code></td>"); ?>
|
|
|
230 |
<tr valign='top'>
|
231 |
<th>Before / after related entries:</th>
|
232 |
<td><input name="before_related" type="text" id="before_related" value="<?php echo stripslashes(yarpp_get_option('before_related',true)); ?>" size="10" /> / <input name="after_related" type="text" id="after_related" value="<?php echo stripslashes(yarpp_get_option('after_related',true)); ?>" size="10" /><em><small> For example: <ol></ol> or <div></div></small></em>
|
233 |
</td>
|
234 |
</tr>
|
235 |
<tr valign='top'>
|
236 |
-
<th>Before / after each
|
237 |
<td><input name="before_title" type="text" id="before_title" value="<?php echo stripslashes(yarpp_get_option('before_title',true)); ?>" size="10" /> / <input name="after_title" type="text" id="after_title" value="<?php echo stripslashes(yarpp_get_option('after_title',true)); ?>" size="10" /><em><small> For example: <li></li> or <dl></dl></small></em>
|
238 |
</td>
|
239 |
</tr>
|
240 |
-
<?php checkbox('show_excerpt',"Show excerpt?","<tr valign='top'><th colspan='2'>",'
|
241 |
<?php textbox('excerpt_length','Excerpt length (No. of words):',null,"<tr name='excerpted' valign='top' ".(yarpp_get_option('show_excerpt')?'':"style='display:none'").">
|
242 |
<th>")?>
|
243 |
|
@@ -249,7 +311,7 @@ checkbox('auto_display',"Automatically display related posts? <a href='#' class=
|
|
249 |
|
250 |
<tr name="excerpted" valign='top'>
|
251 |
<th>Order results:</th>
|
252 |
-
<td><select name="order" id="
|
253 |
<option value="score DESC" <?php echo (yarpp_get_option('order')=='score DESC'?' selected="selected"':'')?>>score (high relevance to low)</option>
|
254 |
<option value="score ASC" <?php echo (yarpp_get_option('order')=='score ASC'?' selected="selected"':'')?>>score (low relevance to high)</option>
|
255 |
<option value="post_date DESC" <?php echo (yarpp_get_option('order')=='post_date DESC'?' selected="selected"':'')?>>date (new to old)</option>
|
@@ -261,12 +323,72 @@ checkbox('auto_display',"Automatically display related posts? <a href='#' class=
|
|
261 |
</tr>
|
262 |
|
263 |
<?php textbox('no_results','Default display if no results:','40')?>
|
264 |
-
<?php checkbox('show_past_post',"Show password protected posts?"); ?>
|
265 |
-
<?php checkbox('past_only',"Show only previous posts?"); ?>
|
266 |
<?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>"); ?>
|
267 |
<?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>"); ?>
|
268 |
</table>
|
|
|
|
|
|
|
269 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
270 |
<div>
|
271 |
<p class="submit">
|
272 |
<input type="submit" name="update_yarpp" value="Update options" />
|
1 |
<?php
|
2 |
// Begin Related Posts Options
|
3 |
|
4 |
+
global $wpdb, $yarpp_value_options, $yarpp_binary_options, $wp_version;
|
5 |
+
|
6 |
+
$yarpp_myisam = true;
|
7 |
+
if (!yarpp_myisam_check()) {
|
8 |
+
echo "<div class='updated'>Your database's <code>$wpdb->posts</code> table is not set up to use the <a href='http://dev.mysql.com/doc/refman/5.0/en/storage-engines.html'>MyISAM storage engine</a> which is required for YARPP to use the \"consider titles\" and \"consider bodies\" criteria. These two options have been disabled.<br />
|
9 |
+
|
10 |
+
To restore these features, please update your <code>$wpdb->posts</code> by executing the following SQL directive: <code>ALTER TABLE `$wpdb->posts` ENGINE = MyISAM;</code> . No data will be erased by altering the table's engine, although there are performance implications.</div>";
|
11 |
+
|
12 |
+
yarpp_set_option('title',1);
|
13 |
+
yarpp_set_option('body',1);
|
14 |
+
$yarpp_myisam = false;
|
15 |
+
}
|
16 |
+
|
17 |
+
$yarpp_twopointfive = true;
|
18 |
+
if (substr($wp_version,0,3) < 2.5) {
|
19 |
+
echo "<div class='updated'>The \"consider tags\" and \"consider categories\" options require WordPress version 2.5. These two options have been disabled.</div>";
|
20 |
+
|
21 |
+
yarpp_set_option('categories',1);
|
22 |
+
yarpp_set_option('tags',1);
|
23 |
+
$yarpp_twopointfive = false;
|
24 |
+
}
|
25 |
+
|
26 |
+
if ($yarpp_myisam) {
|
27 |
+
if (!yarpp_enabled()) {
|
28 |
+
echo '<div class="updated">';
|
29 |
+
if (yarpp_activate())
|
30 |
+
echo 'The YARPP database had an error but has been fixed.';
|
31 |
+
else
|
32 |
+
echo 'The YARPP database has an error which could not be fixed.';
|
33 |
+
echo '</div>';
|
34 |
+
}
|
35 |
}
|
36 |
|
37 |
yarpp_reinforce(); // just in case, set default options, etc.
|
56 |
foreach (array_keys($yarpp_value_options) as $option) {
|
57 |
yarpp_set_option($option,addslashes($_POST[$option]));
|
58 |
}
|
59 |
+
foreach (array('title','body','tags','categories') as $key) {
|
60 |
+
if (!isset($_POST[$key])) yarpp_set_option($key,1);
|
61 |
+
}
|
62 |
if (isset($_POST['discats'])) {
|
63 |
yarpp_set_option('discats',implode(',',array_keys($_POST['discats']))); // discats is different
|
64 |
} else {
|
131 |
|
132 |
?>
|
133 |
<script type="text/javascript">
|
134 |
+
//<!--
|
135 |
+
|
136 |
+
var rss=document.createElement("link");
|
137 |
+
rss.setAttribute("rel", "alternate");
|
138 |
+
rss.setAttribute("type", "application/rss+xml");
|
139 |
+
rss.setAttribute('title',"Yet Another Related Posts Plugin version history (RSS 2.0)");
|
140 |
+
rss.setAttribute("href", "http://mitcho.com/code/yarpp/yarpp.rss");
|
141 |
+
document.getElementsByTagName("head")[0].appendChild(rss);
|
142 |
|
143 |
var css=document.createElement("link");
|
144 |
css.setAttribute("rel", "stylesheet");
|
145 |
css.setAttribute("type", "text/css");
|
146 |
css.setAttribute("href", "../wp-content/plugins/yet-another-related-posts-plugin/options.css");
|
147 |
document.getElementsByTagName("head")[0].appendChild(css);
|
148 |
+
document.getElementsByTagName("body")[0].setAttribute('onload',"excerpt();rss_excerpt();do_rss_display();");
|
149 |
+
//-->
|
150 |
</script>
|
151 |
|
152 |
<div class="wrap">
|
172 |
<form method="post">
|
173 |
|
174 |
|
175 |
+
<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>
|
176 |
|
177 |
|
178 |
<!--The Pool-->
|
179 |
<h3>"The Pool"</h3>
|
180 |
<p>"The Pool" refers to the pool of posts and pages that are candidates for display as related to the current entry.</p>
|
181 |
|
182 |
+
<table class="form-table" style="margin-top: 0">
|
183 |
<tbody>
|
184 |
<tr valign='top'>
|
185 |
<th scope='row'>Disallow by category:</th><td><div style="overflow:auto;max-height:100px;">
|
187 |
$discats = explode(',',yarpp_get_option('discats'));
|
188 |
array_unshift($discats,' ');
|
189 |
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) {
|
190 |
+
echo "<input type='checkbox' name='discats[$cat->term_id]' value='true'". (array_search($cat->term_id,$discats) ? ' checked="checked"': '' )." /> <label>$cat->name</label> ";//for='discats[$cat->term_id]' it's not HTML. :(
|
191 |
}?>
|
192 |
+
</div></td></tr>
|
|
|
193 |
<tr valign='top'>
|
194 |
<th scope='row'>Disallow by tag: </th>
|
195 |
<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(yarpp_get_option($option))))));?>' size='40' />-->
|
197 |
$distags = explode(',',yarpp_get_option('distags'));
|
198 |
array_unshift($distags,' ');
|
199 |
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) {
|
200 |
+
echo "<input type='checkbox' name='distags[$tag->term_id]' value='true'". (array_search($tag->term_id,$distags) ? ' checked="checked"': '' )." /> <label>$tag->name</label> ";// for='distags[$tag->term_id]'
|
201 |
}?>
|
202 |
+
</div></td></tr>
|
203 |
+
<?php checkbox('show_past_post',"Show password protected posts?"); ?>
|
204 |
+
<?php checkbox('past_only',"Show only previous posts?"); ?>
|
205 |
</tbody>
|
206 |
</table>
|
207 |
|
209 |
<h3>"Relatedness" options</h3>
|
210 |
<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>
|
211 |
|
212 |
+
<table class="form-table" style="margin-top: 0">
|
213 |
<tbody>
|
|
|
214 |
|
215 |
<!-- <div id="mySlider"><span>do not consider</span>
|
216 |
<span>consider</span>
|
219 |
</div>-->
|
220 |
|
221 |
<?php textbox('threshold','Match threshold:')?>
|
222 |
+
<?php importance2('title',"Titles: ",'word',"<tr valign='top'>
|
223 |
+
<th scope='row'>",(!$yarpp_myisam?' readonly="readonly" disabled="disabled"':''))?>
|
224 |
+
<?php importance2('body',"Bodies: ",'word',"<tr valign='top'>
|
225 |
+
<th scope='row'>",(!$yarpp_myisam?' readonly="readonly" disabled="disabled"':''))?>
|
226 |
+
<?php importance('tags',"Tags: ",'tag',"<tr valign='top'>
|
227 |
+
<th scope='row'>",(!$yarpp_twopointfive?' readonly="readonly" disabled="disabled"':''))?>
|
228 |
+
<?php importance('categories',"Categories: ",'category',"<tr valign='top'>
|
229 |
+
<th scope='row'>",(!$yarpp_twopointfive?' readonly="readonly" disabled="disabled"':''))?>
|
230 |
<?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>"); ?>
|
231 |
</tbody>
|
232 |
</table>
|
233 |
|
234 |
<script language="javascript">
|
235 |
+
//<!--
|
236 |
function excerpt() {
|
237 |
+
display = 'none';
|
238 |
+
if (document.getElementsByName('show_excerpt')[0].checked) {
|
239 |
+
display = 'table-row';
|
240 |
+
}
|
241 |
+
document.getElementsByName('excerpted')[0].style.display = display;
|
242 |
+
document.getElementsByName('excerpted')[1].style.display = display;
|
243 |
+
}
|
244 |
+
function rss_excerpt() {
|
245 |
+
display = 'none';
|
246 |
+
if (document.getElementsByName('rss_display')[0].checked && document.getElementsByName('rss_show_excerpt')[0].checked) {
|
247 |
+
display = 'table-row';
|
248 |
+
}
|
249 |
+
document.getElementsByName('rss_excerpted')[0].style.display = display;
|
250 |
+
document.getElementsByName('rss_excerpted')[1].style.display = display;
|
251 |
+
}
|
252 |
+
function do_rss_display() {
|
253 |
+
display = 'none';
|
254 |
+
if (document.getElementsByName('rss_display')[0].checked) {
|
255 |
+
rss_excerpt();
|
256 |
+
display = 'table-row';
|
257 |
}
|
258 |
+
document.getElementsByName('rss_displayed')[0].style.display = display;
|
259 |
+
document.getElementsByName('rss_displayed')[1].style.display = display;
|
260 |
+
document.getElementsByName('rss_displayed')[2].style.display = display;
|
261 |
+
document.getElementsByName('rss_displayed')[3].style.display = display;
|
262 |
+
document.getElementsByName('rss_displayed')[4].style.display = display;
|
263 |
+
document.getElementsByName('rss_displayed')[5].style.display = display;
|
264 |
+
document.getElementsByName('rss_displayed')[6].style.display = display;
|
265 |
+
document.getElementsByName('rss_displayed')[7].style.display = display;
|
266 |
}
|
267 |
+
//-->
|
|
|
268 |
</script>
|
269 |
|
270 |
|
271 |
<!-- Display options -->
|
272 |
+
<h3>Display options <small>for your website</small></h3>
|
273 |
|
274 |
+
<table class="form-table" style="margin-top: 0">
|
275 |
<?php
|
276 |
// construct the demo code based on current preferences
|
277 |
|
285 |
if (yarpp_get_option('promote_yarpp'))
|
286 |
$democode .= htmlspecialchars("\n<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>");
|
287 |
|
288 |
+
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.</span></a>","<tr valign='top'>
|
289 |
+
<th class='th-full' colspan='2' scope='row'>",'','<td rowspan="11" style="border-left:8px white solid;"><b>Website display code example</b><br /><small>(Update options to reload.)</small><br/>'
|
290 |
."<code><pre style='overflow:auto;width:350px;'>".($democode)."</pre></code></td>"); ?>
|
291 |
+
<?php textbox('limit','Maximum number of related posts:')?>
|
292 |
<tr valign='top'>
|
293 |
<th>Before / after related entries:</th>
|
294 |
<td><input name="before_related" type="text" id="before_related" value="<?php echo stripslashes(yarpp_get_option('before_related',true)); ?>" size="10" /> / <input name="after_related" type="text" id="after_related" value="<?php echo stripslashes(yarpp_get_option('after_related',true)); ?>" size="10" /><em><small> For example: <ol></ol> or <div></div></small></em>
|
295 |
</td>
|
296 |
</tr>
|
297 |
<tr valign='top'>
|
298 |
+
<th>Before / after each related entry:</th>
|
299 |
<td><input name="before_title" type="text" id="before_title" value="<?php echo stripslashes(yarpp_get_option('before_title',true)); ?>" size="10" /> / <input name="after_title" type="text" id="after_title" value="<?php echo stripslashes(yarpp_get_option('after_title',true)); ?>" size="10" /><em><small> For example: <li></li> or <dl></dl></small></em>
|
300 |
</td>
|
301 |
</tr>
|
302 |
+
<?php checkbox('show_excerpt',"Show excerpt?","<tr valign='top'><th colspan='2'>",' onclick="javascript:excerpt()"'); ?>
|
303 |
<?php textbox('excerpt_length','Excerpt length (No. of words):',null,"<tr name='excerpted' valign='top' ".(yarpp_get_option('show_excerpt')?'':"style='display:none'").">
|
304 |
<th>")?>
|
305 |
|
311 |
|
312 |
<tr name="excerpted" valign='top'>
|
313 |
<th>Order results:</th>
|
314 |
+
<td><select name="order" id="order">
|
315 |
<option value="score DESC" <?php echo (yarpp_get_option('order')=='score DESC'?' selected="selected"':'')?>>score (high relevance to low)</option>
|
316 |
<option value="score ASC" <?php echo (yarpp_get_option('order')=='score ASC'?' selected="selected"':'')?>>score (low relevance to high)</option>
|
317 |
<option value="post_date DESC" <?php echo (yarpp_get_option('order')=='post_date DESC'?' selected="selected"':'')?>>date (new to old)</option>
|
323 |
</tr>
|
324 |
|
325 |
<?php textbox('no_results','Default display if no results:','40')?>
|
|
|
|
|
326 |
<?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>"); ?>
|
327 |
<?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>"); ?>
|
328 |
</table>
|
329 |
+
|
330 |
+
<!-- Display options for RSS -->
|
331 |
+
<h3>Display options <small>for RSS</small> <span style='color:red;'>NEW!</span></h3>
|
332 |
|
333 |
+
<table class="form-table" style="margin-top: 0">
|
334 |
+
<?php
|
335 |
+
// construct the demo code based on current preferences for RSS
|
336 |
+
|
337 |
+
$democode = stripslashes(yarpp_get_option('rss_before_related',true))."
|
338 |
+
";
|
339 |
+
for ($i=1;$i<=yarpp_get_option('rss_limit');$i++) {
|
340 |
+
$democode .= stripslashes(yarpp_get_option('rss_before_title',true)).stripslashes(htmlspecialchars("<a href='PERMALINK$i'>RELATED TITLE $i</a>")).(yarpp_get_option('rss_show_excerpt')?"\r\t".stripslashes(yarpp_get_option('rss_before_post',true)).yarpp_excerpt(LOREMIPSUM,yarpp_get_option('rss_excerpt_length')).stripslashes(yarpp_get_option('rss_before_post',true)):'').stripslashes(yarpp_get_option('rss_after_title',true))."
|
341 |
+
";
|
342 |
+
}
|
343 |
+
$democode .= stripslashes(yarpp_get_option('rss_after_related',true));
|
344 |
+
if (yarpp_get_option('rss_promote_yarpp'))
|
345 |
+
$democode .= htmlspecialchars("\n<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>");
|
346 |
+
|
347 |
+
checkbox('rss_display',"Display related posts in feeds? <a href='#' class='info'>more><span>This option displays related posts at the end of each item in your RSS and Atom feeds. No template changes are needed.</span></a>","<tr valign='top'><th colspan='3'>",' onclick="javascript:do_rss_display();"');
|
348 |
+
checkbox('rss_excerpt_display',"Display related posts in the descriptions? <a href='#' class='info'>more><span>This option displays the related posts in the RSS description fields, not just the content. If your feeds are set up to only display excerpts, however, only the description field is used, so this option is required for any display at all.</span></a>","<tr name='rss_displayed' valign='top'>
|
349 |
+
<th class='th-full' colspan='2' scope='row'>",'','<td rowspan="10" style="border-left:8px white solid;"><b>RSS display code example</b><br /><small>(Update options to reload.)</small><br/>'
|
350 |
+
."<code><pre style='overflow:auto;width:350px;'>".($democode)."</pre></code></td>"); ?>
|
351 |
+
<?php textbox('rss_limit','Maximum number of related posts:',2,"<tr valign='top' name='rss_displayed'>
|
352 |
+
<th scope='row'>")?>
|
353 |
+
<tr name='rss_displayed' valign='top'>
|
354 |
+
<th>Before / after related entries display:</th>
|
355 |
+
<td><input name="rss_before_related" type="text" id="rss_before_related" value="<?php echo stripslashes(yarpp_get_option('rss_before_related',true)); ?>" size="10" /> / <input name="rss_after_related" type="text" id="rss_after_related" value="<?php echo stripslashes(yarpp_get_option('rss_after_related',true)); ?>" size="10" /><em><small> For example: <ol></ol> or <div></div></small></em>
|
356 |
+
</td>
|
357 |
+
</tr>
|
358 |
+
<tr name='rss_displayed' valign='top'>
|
359 |
+
<th>Before / after each related entry:</th>
|
360 |
+
<td><input name="rss_before_title" type="text" id="rss_before_title" value="<?php echo stripslashes(yarpp_get_option('rss_before_title',true)); ?>" size="10" /> / <input name="rss_after_title" type="text" id="rss_after_title" value="<?php echo stripslashes(yarpp_get_option('rss_after_title',true)); ?>" size="10" /><em><small> For example: <li></li> or <dl></dl></small></em>
|
361 |
+
</td>
|
362 |
+
</tr>
|
363 |
+
<?php checkbox('rss_show_excerpt',"Show excerpt?","<tr name='rss_displayed' valign='top'><th colspan='2'>",' onclick="javascript:rss_excerpt()"'); ?>
|
364 |
+
<?php textbox('rss_excerpt_length','Excerpt length (No. of words):',null,"<tr name='rss_excerpted' valign='top' ".(yarpp_get_option('rss_show_excerpt')?'':"style='display:none'").">
|
365 |
+
<th>")?>
|
366 |
+
|
367 |
+
<tr name="rss_excerpted" valign='top' <?php echo (yarpp_get_option('rss_show_excerpt')?'':"style='display:none'")?>>
|
368 |
+
<th>Before / after (Excerpt):</th>
|
369 |
+
<td><input name="rss_before_post" type="text" id="rss_before_post" value="<?php echo stripslashes(yarpp_get_option('rss_before_post',true)); ?>" size="10" /> / <input name="rss_after_post" type="text" id="rss_after_post" value="<?php echo stripslashes(yarpp_get_option('rss_after_post')); ?>" size="10" /><em><small> For example: <li></li> or <dl></dl></small></em>
|
370 |
+
</td>
|
371 |
+
</tr>
|
372 |
+
|
373 |
+
<tr name='rss_displayed' valign='top'>
|
374 |
+
<th>Order results:</th>
|
375 |
+
<td><select name="rss_order" id="rss_order">
|
376 |
+
<option value="score DESC" <?php echo (yarpp_get_option('rss_order')=='score DESC'?' selected="selected"':'')?>>score (high relevance to low)</option>
|
377 |
+
<option value="score ASC" <?php echo (yarpp_get_option('rss_order')=='score ASC'?' selected="selected"':'')?>>score (low relevance to high)</option>
|
378 |
+
<option value="post_date DESC" <?php echo (yarpp_get_option('rss_order')=='post_date DESC'?' selected="selected"':'')?>>date (new to old)</option>
|
379 |
+
<option value="post_date ASC" <?php echo (yarpp_get_option('rss_order')=='post_date ASC'?' selected="selected"':'')?>>date (old to new)</option>
|
380 |
+
<option value="post_title ASC" <?php echo (yarpp_get_option('rss_order')=='post_title ASC'?' selected="selected"':'')?>>title (alphabetical)</option>
|
381 |
+
<option value="post_title DESC" <?php echo (yarpp_get_option('rss_order')=='post_title DESC'?' selected="selected"':'')?>>title (reverse alphabetical)</option>
|
382 |
+
</select>
|
383 |
+
</td>
|
384 |
+
</tr>
|
385 |
+
|
386 |
+
<?php textbox('rss_no_results','Default display if no results:','40',"<tr valign='top' name='rss_displayed'>
|
387 |
+
<th scope='row'>")?>
|
388 |
+
<?php checkbox('rss_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>","<tr valign='top' name='rss_displayed'>
|
389 |
+
<th class='th-full' colspan='2' scope='row'>"); ?>
|
390 |
+
</table>
|
391 |
+
|
392 |
<div>
|
393 |
<p class="submit">
|
394 |
<input type="submit" name="update_yarpp" value="Update options" />
|
readme.txt
CHANGED
@@ -4,43 +4,101 @@ Author: mitcho (Michael Yoshitaka Erlewine)
|
|
4 |
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.3
|
9 |
-
Tested up to: 2.
|
10 |
-
Stable tag: 2.
|
11 |
|
12 |
-
Returns a list of the related entries based on
|
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. *
|
21 |
-
4. *
|
22 |
-
5. *
|
23 |
-
6. *
|
|
|
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 |
= Widget =
|
32 |
|
33 |
Related posts can also be displayed as a widget. Go to the Design > Widgets options page and add the Related Posts widget. The widget will only be displayed on single entry (permalink) pages. The widget can be used even if the "auto display" option is turned off.
|
34 |
|
35 |
= Manual installation =
|
36 |
|
|
|
|
|
37 |
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.
|
38 |
|
39 |
There're also `related_posts_exist()`, `related_pages_exist()`, and `related_entries_exist()` functions, which return a boolean as expected.
|
40 |
|
41 |
-
|
42 |
-
|
43 |
-
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.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
|
45 |
== Frequently Asked Questions ==
|
46 |
|
@@ -50,6 +108,12 @@ If your question isn't here, ask your own question at [the Wordpress.org forums]
|
|
50 |
|
51 |
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.
|
52 |
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
= A weird number is displayed after each related post. What is this? =
|
54 |
|
55 |
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.
|
@@ -109,12 +173,21 @@ I highly recommend you disactivate YARPP, replace it with the new one, and then
|
|
109 |
* A helpful little tooltip for the admin-only threshold display
|
110 |
* 2.0.6
|
111 |
* A quick emergency bugfix (In one instance, assumed existence of `wp_posts`)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
112 |
|
113 |
== Future versions ==
|
114 |
|
115 |
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).
|
116 |
|
117 |
* User-defineable stopwords, especially to support other languages, [by request](http://wordpress.org/support/topic/159359)
|
|
|
118 |
* Date and comment count in excerpt, [by request](http://wordpress.org/support/topic/156231)
|
119 |
-
* RSS feed support: an option to automagically show related posts in RSS feeds, [by popular request](http://wordpress.org/support/topic/151766).
|
120 |
* Sentece-aware excerpts, [by request](http://wordpress.org/support/topic/162465)
|
4 |
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, RSS, feed, feeds
|
8 |
Requires at least: 2.3
|
9 |
+
Tested up to: 2.7
|
10 |
+
Stable tag: 2.1
|
11 |
|
12 |
+
Returns a list of the related entries based on a unique algorithm using titles, post bodies, tags, and categories. Now with RSS feed support!
|
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](http://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. *Related posts in RSS feeds*: **New in 2.1!** Display related posts in your RSS and Atom feeds with custom display options.
|
21 |
+
4. *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.
|
22 |
+
5. *Related posts and pages*: **New in 1.1!** Puts you in control of pulling up related posts, pages, or both.
|
23 |
+
6. *Simple installation*: **New in 1.5!** Automatically displays related posts after content on single entry pages without any theme tinkering.
|
24 |
+
7. *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.
|
25 |
|
26 |
== Installation ==
|
27 |
|
28 |
+
= Auto display on your website =
|
29 |
|
30 |
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.
|
31 |
|
32 |
+
= Auto display in your feeds =
|
33 |
+
|
34 |
+
Since YARPP 2.1, you can turn on the "display related posts in feeds" option to show related posts in your RSS and Atom feeds.
|
35 |
+
|
36 |
+
The "display related posts in feeds" option can be used regardless of whether you auto display them on your website (and vice versa).
|
37 |
+
|
38 |
= Widget =
|
39 |
|
40 |
Related posts can also be displayed as a widget. Go to the Design > Widgets options page and add the Related Posts widget. The widget will only be displayed on single entry (permalink) pages. The widget can be used even if the "auto display" option is turned off.
|
41 |
|
42 |
= Manual installation =
|
43 |
|
44 |
+
**This is an advanced feature for those comfortable with PHP.** 97% of users will be better served by the auto display options above.
|
45 |
+
|
46 |
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.
|
47 |
|
48 |
There're also `related_posts_exist()`, `related_pages_exist()`, and `related_entries_exist()` functions, which return a boolean as expected.
|
49 |
|
50 |
+
**The `related_` functions**
|
51 |
+
|
52 |
+
By default, `related_posts()` gives you back posts only, `related_pages()` gives you pages, and there's `related_entries()` which 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.
|
53 |
+
|
54 |
+
The `related` functions can be used in conjunction to the regular "auto display" option.
|
55 |
+
|
56 |
+
**Customizing the `related_` functions**
|
57 |
+
|
58 |
+
Since YARPP 2.1, you can specify some custom options for each instance of `related_*()`. The arguments are specified as a single array argument (`related_*(array(key=>value, key=>value, ...))`).
|
59 |
+
|
60 |
+
The available keys in version 2.1 are (roughly in the same order as in the options page):
|
61 |
+
|
62 |
+
* The Pool:
|
63 |
+
* `distags` => comma-delimited list of tag numbers which should be disallowed
|
64 |
+
* `discats` => comma-delimited list of category numbers which should be disallowed
|
65 |
+
* Relatedness options:
|
66 |
+
* `threshold` => the match threshold
|
67 |
+
* `show_pass_post` => (`bool`) show password-protected posts
|
68 |
+
* `past_only` => (`bool`) only past posts
|
69 |
+
* `title` => 1 for "do not consider", 2 for "consider", 3 for "consider with extra weight"
|
70 |
+
* `body` => 1 for "do not consider", 2 for "consider", 3 for "consider with extra weight"
|
71 |
+
* `tags` => 1 for "do not consider", 2 for "consider", 3 for "require one common tag", 4 for "require multiple common tags"
|
72 |
+
* `categories` => 1 for "do not consider", 2 for "consider", 3 for "require one common category", 4 for "require multiple common categories"
|
73 |
+
* `cross_relate` => (`bool`) cross-relate posts and pages
|
74 |
+
* Display options:
|
75 |
+
* `limit` => (`int`) maximum number of results
|
76 |
+
* `before_related` => before related entries text
|
77 |
+
* `after_related` => after related entries text
|
78 |
+
* `before_title` => before related entry title text
|
79 |
+
* `after_title` => after related entry title text
|
80 |
+
* `show_excerpt` => (`bool`) show excerpt
|
81 |
+
* `excerpt_length` => (`int`) the excerpt length
|
82 |
+
* `before_post` => before each related entry text
|
83 |
+
* `after_post` => after each related entry text
|
84 |
+
* `order` => MySQL `ORDER BY ` field and direction
|
85 |
+
* `no_results` => "no results" text
|
86 |
+
* `promote_yarpp` => (`bool`) promote YARPP?
|
87 |
+
* `show_score` => (`bool`) show the match score to admins
|
88 |
+
|
89 |
+
**Examples**
|
90 |
+
|
91 |
+
Customized `related_*()` functions can be used to build specialized related-post functionality into your WordPress-enabled site. Here are some examples to get you started:
|
92 |
+
|
93 |
+
* `related_posts(array('title'=>1,'body'=>1,'tags'=>1,'categories'=>3))`
|
94 |
+
* This example will return posts with at least one common category (with no other considerations).
|
95 |
+
* `related_posts(array('show_pass_post'=>1))`
|
96 |
+
* This example will return password-protected posts.
|
97 |
+
* This is useful for a site with some members-only content. This command can be run within a `if ($membership == true)` type of conditional.
|
98 |
+
* `related_posts(array('order'=>'rand() asc','limit'=>1))`
|
99 |
+
* This example will link to one random related post.
|
100 |
+
* `related_posts(array('discats'=>'`(all categories except one)`'))`
|
101 |
+
* This example will give you related posts from only a certain category. (Although there are certainly much better ways to do this with other plugins or custom code.)
|
102 |
|
103 |
== Frequently Asked Questions ==
|
104 |
|
108 |
|
109 |
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.
|
110 |
|
111 |
+
= I turned off one of the relatedness criteria (titles, bodies, tags, or categories) and now every page says "no related posts"! =
|
112 |
+
|
113 |
+
This has to do with the way the "match score" is computed. Every entry's match score is the weighted sum of its title-score, body-score, tag-score, and category-score. If you turn off one of the relatedness criteria, you will no doubt have to lower your match threshold to get the same number of related entries to show up. Alternatively, you can consider one of the other criteria "with extra weight".
|
114 |
+
|
115 |
+
It is recommended that you tweak your match threshold whenever you make changes to the "makeup" of your match score (i.e., the settings for the titles, bodies, tags, and categories items).
|
116 |
+
|
117 |
= A weird number is displayed after each related post. What is this? =
|
118 |
|
119 |
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.
|
173 |
* A helpful little tooltip for the admin-only threshold display
|
174 |
* 2.0.6
|
175 |
* A quick emergency bugfix (In one instance, assumed existence of `wp_posts`)
|
176 |
+
* 2.1 - The RSS edition!
|
177 |
+
* RSS feed support!: the option to automagically show related posts in RSS feeds and to customize their display, [by popular request](http://wordpress.org/support/topic/151766).
|
178 |
+
* A link to [the Yet Another Related Posts Plugin RSS feed](http://wordpress.org/support/topic/208469).
|
179 |
+
* Further optimization of the main SQL query in cases where not all of the match criteria (title, body, tags, categories) are chosen.
|
180 |
+
* A new format for pushing arguments to the `related_posts()` functions.
|
181 |
+
* Bugfix: [compatibility](http://wordpress.org/support/topic/207286) with the [dzoneZ-Et](http://wordpress.org/extend/plugins/dzonez-et/) and [reddZ-Et](http://wordpress.org/extend/plugins/reddz-et/) plugins.
|
182 |
+
* Bugfix: `related_*_exist()` functions produced invalid queries
|
183 |
+
* A warning for `wp_posts` with non-MyISAM engines and semi-compatibility with non-MyISAM setups.
|
184 |
+
* Bugfix: [a better notice for users of Wordpress < 2.5](http://www.mattcutts.com/blog/wordpress-plugin-related-posts/#comment-131194) regarding the "compare tags" and "compare categories" features.
|
185 |
|
186 |
== Future versions ==
|
187 |
|
188 |
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).
|
189 |
|
190 |
* User-defineable stopwords, especially to support other languages, [by request](http://wordpress.org/support/topic/159359)
|
191 |
+
* Localization
|
192 |
* Date and comment count in excerpt, [by request](http://wordpress.org/support/topic/156231)
|
|
|
193 |
* Sentece-aware excerpts, [by request](http://wordpress.org/support/topic/162465)
|
related-functions.php
CHANGED
@@ -2,33 +2,29 @@
|
|
2 |
|
3 |
// Here are the related_WHATEVER functions, as introduced in 1.1, which actually just use the yarpp_related and yarpp_related_exist functions.
|
4 |
|
5 |
-
|
6 |
-
|
|
|
7 |
return yarpp_related(array('post'),$a);
|
8 |
}
|
9 |
|
10 |
-
function related_pages() {
|
11 |
-
$a = func_get_args();
|
12 |
return yarpp_related(array('page'),$a);
|
13 |
}
|
14 |
|
15 |
-
function related_entries() {
|
16 |
-
$a = func_get_args();
|
17 |
return yarpp_related(array('page','post'),$a);
|
18 |
}
|
19 |
|
20 |
-
function related_posts_exist() {
|
21 |
-
$a = func_get_args();
|
22 |
return yarpp_related_exist(array('post'),$a);
|
23 |
}
|
24 |
|
25 |
-
function related_pages_exist() {
|
26 |
-
$a = func_get_args();
|
27 |
return yarpp_related_exist(array('page'),$a);
|
28 |
}
|
29 |
|
30 |
-
function related_entries_exist() {
|
31 |
-
$a = func_get_args();
|
32 |
return yarpp_related_exist(array('page','post'),$a);
|
33 |
}
|
34 |
|
2 |
|
3 |
// Here are the related_WHATEVER functions, as introduced in 1.1, which actually just use the yarpp_related and yarpp_related_exist functions.
|
4 |
|
5 |
+
// Since YARPP 2.1, these functions receive (optionally) one array argument. See the documentation for instructions on how to customize their output.
|
6 |
+
|
7 |
+
function related_posts($a = array()) {
|
8 |
return yarpp_related(array('post'),$a);
|
9 |
}
|
10 |
|
11 |
+
function related_pages($a = array()) {
|
|
|
12 |
return yarpp_related(array('page'),$a);
|
13 |
}
|
14 |
|
15 |
+
function related_entries($a = array()) {
|
|
|
16 |
return yarpp_related(array('page','post'),$a);
|
17 |
}
|
18 |
|
19 |
+
function related_posts_exist($a = array()) {
|
|
|
20 |
return yarpp_related_exist(array('post'),$a);
|
21 |
}
|
22 |
|
23 |
+
function related_pages_exist($a = array()) {
|
|
|
24 |
return yarpp_related_exist(array('page'),$a);
|
25 |
}
|
26 |
|
27 |
+
function related_entries_exist($a = array()) {
|
|
|
28 |
return yarpp_related_exist(array('page','post'),$a);
|
29 |
}
|
30 |
|
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
|
6 |
-
Version: 2.
|
7 |
Author: mitcho (Michael Yoshitaka Erlewine)
|
8 |
*/
|
9 |
|
@@ -14,6 +14,8 @@ require_once('related-functions.php');
|
|
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
|
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 a unique algorithm using titles, post bodies, tags, and categories. Now with RSS feed support!
|
6 |
+
Version: 2.1
|
7 |
Author: mitcho (Michael Yoshitaka Erlewine)
|
8 |
*/
|
9 |
|
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 |
+
add_filter('the_content_rss','yarpp_rss',600);
|
18 |
+
add_filter('the_excerpt_rss','yarpp_rss_excerpt',600);
|
19 |
register_activation_hook(__FILE__,'yarpp_activate');
|
20 |
|
21 |
// new in 2.0: add as a widget
|