Version Description
- Post Except
- Thumbnail
- Widget
Download this release
Release Info
Developer | denishua |
Plugin | WordPress Related Posts |
Version | 1.1 |
Comparing to | |
See all releases |
Code changes from version 0.6 to 1.1
- Thumbs.db +0 -0
- WPRP/wp_related_posts.php +0 -391
- {WPRP/lang → lang}/default.po +0 -0
- {WPRP/lang → lang}/wp_related_posts-zh_CN.mo +0 -0
- {WPRP/lang → lang}/wp_related_posts-zh_CN.po +1 -1
- readme.txt +12 -11
- screenshot-1.jpg +0 -0
- screenshot-1.png +0 -0
- wp_related_posts.php +502 -0
Thumbs.db
CHANGED
Binary file
|
WPRP/wp_related_posts.php
DELETED
@@ -1,391 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
/*
|
3 |
-
Plugin Name: WordPress Related Posts
|
4 |
-
Version: 0.8
|
5 |
-
Plugin URI: http://fairyfish.net/2007/09/12/wordpress-23-related-posts-plugin/
|
6 |
-
Description: Generate a related posts list via tags of WordPress
|
7 |
-
Author: Denis
|
8 |
-
Author URI: http://fairyfish.net/
|
9 |
-
|
10 |
-
Copyright (c) 2007
|
11 |
-
Released under the GPL license
|
12 |
-
http://www.gnu.org/licenses/gpl.txt
|
13 |
-
|
14 |
-
This file is part of WordPress.
|
15 |
-
WordPress is free software; you can redistribute it and/or modify
|
16 |
-
it under the terms of the GNU General Public License as published by
|
17 |
-
the Free Software Foundation; either version 2 of the License, or
|
18 |
-
(at your option) any later version.
|
19 |
-
|
20 |
-
This program is distributed in the hope that it will be useful,
|
21 |
-
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
22 |
-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
23 |
-
GNU General Public License for more details.
|
24 |
-
|
25 |
-
You should have received a copy of the GNU General Public License
|
26 |
-
along with this program; if not, write to the Free Software
|
27 |
-
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
28 |
-
|
29 |
-
INSTALL:
|
30 |
-
Just install the plugin in your blog and activate
|
31 |
-
*/
|
32 |
-
|
33 |
-
load_plugin_textdomain('wp_related_posts',PLUGINDIR . '/' . dirname(plugin_basename (__FILE__)) . '/lang');
|
34 |
-
|
35 |
-
function wp_get_related_posts() {
|
36 |
-
global $wpdb, $post,$table_prefix;
|
37 |
-
$wp_rp = get_option("wp_rp");
|
38 |
-
|
39 |
-
$exclude = explode(",",$wp_rp["wp_rp_exclude"]);
|
40 |
-
$limit = $wp_rp["wp_rp_limit"];
|
41 |
-
$wp_rp_title = $wp_rp["wp_rp_title"];
|
42 |
-
$wp_no_rp = $wp_rp["wp_no_rp"];
|
43 |
-
$wp_no_rp_text = $wp_rp["wp_no_rp_text"];
|
44 |
-
$show_date = $wp_rp["wp_rp_date"];
|
45 |
-
$show_comments_count = $wp_rp["wp_rp_comments"];
|
46 |
-
|
47 |
-
if ( $exclude != '' ) {
|
48 |
-
$q = "SELECT tt.term_id FROM ". $table_prefix ."term_taxonomy tt, " . $table_prefix . "term_relationships tr WHERE tt.taxonomy = 'category' AND tt.term_taxonomy_id = tr.term_taxonomy_id AND tr.object_id = $post->ID";
|
49 |
-
|
50 |
-
$cats = $wpdb->get_results($q);
|
51 |
-
|
52 |
-
foreach(($cats) as $cat) {
|
53 |
-
if (in_array($cat->term_id, $exclude) != false){
|
54 |
-
return;
|
55 |
-
}
|
56 |
-
}
|
57 |
-
}
|
58 |
-
|
59 |
-
if(!$post->ID){return;}
|
60 |
-
$now = current_time('mysql', 1);
|
61 |
-
$tags = wp_get_post_tags($post->ID);
|
62 |
-
|
63 |
-
//print_r($tags);
|
64 |
-
|
65 |
-
$taglist = "'" . $tags[0]->term_id. "'";
|
66 |
-
|
67 |
-
$tagcount = count($tags);
|
68 |
-
if ($tagcount > 1) {
|
69 |
-
for ($i = 1; $i <= $tagcount; $i++) {
|
70 |
-
$taglist = $taglist . ", '" . $tags[$i]->term_id . "'";
|
71 |
-
}
|
72 |
-
}
|
73 |
-
|
74 |
-
if ($limit) {
|
75 |
-
$limitclause = "LIMIT $limit";
|
76 |
-
} else {
|
77 |
-
$limitclause = "LIMIT 10";
|
78 |
-
}
|
79 |
-
|
80 |
-
$q = "SELECT DISTINCT p.ID, p.post_title, p.post_date, p.comment_count, count(t_r.object_id) as cnt FROM $wpdb->term_taxonomy t_t, $wpdb->term_relationships t_r, $wpdb->posts p WHERE t_t.taxonomy ='post_tag' AND t_t.term_taxonomy_id = t_r.term_taxonomy_id AND t_r.object_id = p.ID AND (t_t.term_id IN ($taglist)) AND p.ID != $post->ID AND p.post_status = 'publish' AND p.post_date_gmt < '$now' GROUP BY t_r.object_id ORDER BY cnt DESC, p.post_date_gmt DESC $limitclause;";
|
81 |
-
|
82 |
-
//echo $q;
|
83 |
-
|
84 |
-
$related_posts = $wpdb->get_results($q);
|
85 |
-
$output = "";
|
86 |
-
|
87 |
-
if (!$related_posts){
|
88 |
-
|
89 |
-
if(!$wp_no_rp || ($wp_no_rp == "popularity" && !function_exists('akpc_most_popular'))) $wp_no_rp = "text";
|
90 |
-
|
91 |
-
if($wp_no_rp == "text"){
|
92 |
-
if(!$wp_no_rp_text) $wp_no_rp_text= __("No Related Post",'wp_related_posts');
|
93 |
-
$output .= '<li>'.$wp_no_rp_text .'</li>';
|
94 |
-
} else{
|
95 |
-
if($wp_no_rp == "random"){
|
96 |
-
if(!$wp_no_rp_text) $wp_no_rp_text= __("Random Posts",'wp_related_posts');
|
97 |
-
$related_posts = wp_get_random_posts($limitclause);
|
98 |
-
} elseif($wp_no_rp == "commented"){
|
99 |
-
if(!$wp_no_rp_text) $wp_no_rp_text= __("Most Commented Posts",'wp_related_posts');
|
100 |
-
$related_posts = wp_get_most_commented_posts($limitclause);
|
101 |
-
} elseif($wp_no_rp == "popularity"){
|
102 |
-
if(!$wp_no_rp_text) $wp_no_rp_text= __("Most Popular Posts",'wp_related_posts');
|
103 |
-
$related_posts = wp_get_most_popular_posts($limitclause);
|
104 |
-
}else{
|
105 |
-
return __("Something wrong",'wp_related_posts');;
|
106 |
-
}
|
107 |
-
$wp_rp_title = $wp_no_rp_text;
|
108 |
-
}
|
109 |
-
}
|
110 |
-
|
111 |
-
foreach ($related_posts as $related_post ){
|
112 |
-
$output .= '<li>';
|
113 |
-
|
114 |
-
if ($show_date){
|
115 |
-
$dateformat = get_option('date_format');
|
116 |
-
$output .= mysql2date($dateformat, $related_post->post_date) . " -- ";
|
117 |
-
}
|
118 |
-
|
119 |
-
$output .= '<a href="'.get_permalink($related_post->ID).'" title="'.wptexturize($related_post->post_title).'">'.wptexturize($related_post->post_title).'';
|
120 |
-
|
121 |
-
if ($show_comments_count){
|
122 |
-
$output .= " (" . $related_post->comment_count . ")";
|
123 |
-
}
|
124 |
-
|
125 |
-
$output .= '</a></li>';
|
126 |
-
}
|
127 |
-
|
128 |
-
$output = '<ul class="related_post">' . $output . '</ul>';
|
129 |
-
|
130 |
-
if($wp_rp_title != '') $output = '<h3>'.$wp_rp_title .'</h3>'. $output;
|
131 |
-
|
132 |
-
return $output;
|
133 |
-
}
|
134 |
-
|
135 |
-
function wp_related_posts(){
|
136 |
-
|
137 |
-
global $id;
|
138 |
-
|
139 |
-
$output_old = get_post_meta($id, "related_posts", $single = true);
|
140 |
-
|
141 |
-
if($output_old){
|
142 |
-
$time = time();
|
143 |
-
if(($time - $output_old["time"])<600){
|
144 |
-
echo $output_old["related_posts"];
|
145 |
-
return;
|
146 |
-
}
|
147 |
-
}
|
148 |
-
|
149 |
-
$output = wp_get_related_posts() ;
|
150 |
-
|
151 |
-
$output_new = array("time"=>time(),"related_posts"=>$output);
|
152 |
-
if($output_old){
|
153 |
-
update_post_meta($id, 'related_posts', $output_new);
|
154 |
-
}else{
|
155 |
-
if(!add_post_meta($id, 'related_posts', $output_new, true)){
|
156 |
-
update_post_meta($id, 'related_posts', $output_new);
|
157 |
-
}
|
158 |
-
}
|
159 |
-
|
160 |
-
echo $output;
|
161 |
-
}
|
162 |
-
|
163 |
-
function wp23_related_posts() {
|
164 |
-
wp_related_posts();
|
165 |
-
}
|
166 |
-
|
167 |
-
function wp_related_posts_for_feed($content=""){
|
168 |
-
$wp_rp = get_option("wp_rp");
|
169 |
-
$wp_rp_rss = ($wp_rp["wp_rp_rss"] == 'yes') ? 1 : 0;
|
170 |
-
if ( (! is_feed()) || (! $wp_rp_rss)) return $content;
|
171 |
-
|
172 |
-
$output = wp_get_related_posts() ;
|
173 |
-
$content = $content . $output;
|
174 |
-
|
175 |
-
return $content;
|
176 |
-
}
|
177 |
-
|
178 |
-
add_filter('the_content', 'wp_related_posts_for_feed',1);
|
179 |
-
|
180 |
-
function wp_related_posts_auto($content=""){
|
181 |
-
$wp_rp = get_option("wp_rp");
|
182 |
-
$wp_rp_auto = ($wp_rp["wp_rp_auto"] == 'yes') ? 1 : 0;
|
183 |
-
if ( (! is_single()) || (! $wp_rp_auto)) return $content;
|
184 |
-
|
185 |
-
$output = wp_get_related_posts() ;
|
186 |
-
$content = $content . $output;
|
187 |
-
|
188 |
-
return $content;
|
189 |
-
}
|
190 |
-
|
191 |
-
add_filter('the_content', 'wp_related_posts_auto',99);
|
192 |
-
|
193 |
-
function wp_get_random_posts ($limitclause="") {
|
194 |
-
global $wpdb, $tableposts, $post;
|
195 |
-
|
196 |
-
$q = "SELECT ID, post_title, post_date, comment_count FROM $tableposts WHERE post_status = 'publish' AND post_type = 'post' AND ID != $post->ID ORDER BY RAND() $limitclause";
|
197 |
-
return $wpdb->get_results($q);
|
198 |
-
}
|
199 |
-
|
200 |
-
function wp_random_posts ($number = 10){
|
201 |
-
$limitclause="LIMIT " . $number;
|
202 |
-
$random_posts = wp_get_random_posts ($limitclause);
|
203 |
-
|
204 |
-
foreach ($random_posts as $random_post ){
|
205 |
-
$output .= '<li>';
|
206 |
-
|
207 |
-
$output .= '<a href="'.get_permalink($random_post->ID).'" title="'.wptexturize($random_post->post_title).'">'.wptexturize($random_post->post_title).'</a></li>';
|
208 |
-
}
|
209 |
-
|
210 |
-
$output = '<ul class="randome_post">' . $output . '</ul>';
|
211 |
-
|
212 |
-
echo $output;
|
213 |
-
}
|
214 |
-
|
215 |
-
function wp_get_most_commented_posts($limitclause="") {
|
216 |
-
global $wpdb;
|
217 |
-
$q = "SELECT ID, post_title, post_date, COUNT($wpdb->comments.comment_post_ID) AS 'comment_count' FROM $wpdb->posts, $wpdb->comments WHERE comment_approved = '1' AND $wpdb->posts.ID=$wpdb->comments.comment_post_ID AND post_status = 'publish' GROUP BY $wpdb->comments.comment_post_ID ORDER BY comment_count DESC $limitclause";
|
218 |
-
return $wpdb->get_results($q);
|
219 |
-
}
|
220 |
-
|
221 |
-
function wp_most_commented_posts ($number = 10){
|
222 |
-
$limitclause="LIMIT " . $number;
|
223 |
-
$most_commented_posts = wp_get_most_commented_posts ($limitclause);
|
224 |
-
|
225 |
-
foreach ($most_commented_posts as $most_commented_post ){
|
226 |
-
$output .= '<li>';
|
227 |
-
|
228 |
-
$output .= '<a href="'.get_permalink($most_commented_post->ID).'" title="'.wptexturize($most_commented_post->post_title).'">'.wptexturize($most_commented_post->post_title).'</a></li>';
|
229 |
-
}
|
230 |
-
|
231 |
-
$output = '<ul class="most_commented_post">' . $output . '</ul>';
|
232 |
-
|
233 |
-
echo $output;
|
234 |
-
}
|
235 |
-
|
236 |
-
function wp_get_most_popular_posts ($limitclause="") {
|
237 |
-
global $wpdb, $table_prefix;
|
238 |
-
|
239 |
-
$q = $sql = "SELECT p.ID, p.post_title, p.post_date, p.comment_count FROM ". $table_prefix ."ak_popularity as akpc,".$table_prefix ."posts as p WHERE p.ID = akpc.post_id ORDER BY akpc.total DESC $limitclause";;
|
240 |
-
return $wpdb->get_results($q);
|
241 |
-
}
|
242 |
-
|
243 |
-
function wp_most_popular_posts ($number = 10){
|
244 |
-
$limitclause="LIMIT " . $number;
|
245 |
-
$most_popular_posts = wp_get_most_popular_posts ($limitclause);
|
246 |
-
|
247 |
-
foreach ($most_popular_posts as $most_popular_post ){
|
248 |
-
$output .= '<li>';
|
249 |
-
|
250 |
-
$output .= '<a href="'.get_permalink($most_popular_post->ID).'" title="'.wptexturize($most_popular_post->post_title).'">'.wptexturize($most_popular_post->post_title).'</a></li>';
|
251 |
-
}
|
252 |
-
|
253 |
-
$output = '<ul class="most_popular_post">' . $output . '</ul>';
|
254 |
-
|
255 |
-
echo $output;
|
256 |
-
}
|
257 |
-
|
258 |
-
add_action('admin_menu', 'wp_add_related_posts_options_page');
|
259 |
-
|
260 |
-
function wp_add_related_posts_options_page() {
|
261 |
-
if (function_exists('add_options_page')) {
|
262 |
-
add_options_page( __('WordPress Related Posts','wp_related_posts'), __('WordPress Related Posts','wp_related_posts'), 8, basename(__FILE__), 'wp_related_posts_options_subpanel');
|
263 |
-
}
|
264 |
-
}
|
265 |
-
|
266 |
-
function wp_related_posts_options_subpanel() {
|
267 |
-
if($_POST["wp_rp_Submit"]){
|
268 |
-
$message = "WordPress Related Posts Setting Updated";
|
269 |
-
|
270 |
-
$wp_rp_saved = get_option("wp_rp");
|
271 |
-
|
272 |
-
$wp_rp = array (
|
273 |
-
"wp_rp_title" => $_POST['wp_rp_title_option'],
|
274 |
-
"wp_no_rp" => $_POST['wp_no_rp_option'],
|
275 |
-
"wp_no_rp_text" => $_POST['wp_no_rp_text_option'],
|
276 |
-
"wp_rp_limit" => $_POST['wp_rp_limit_option'],
|
277 |
-
'wp_rp_exclude' => $_POST['wp_rp_exclude_option'],
|
278 |
-
'wp_rp_auto' => $_POST['wp_rp_auto_option'],
|
279 |
-
'wp_rp_rss' => $_POST['wp_rp_rss_option'],
|
280 |
-
'wp_rp_comments'=> $_POST['wp_rp_comments_option'],
|
281 |
-
'wp_rp_date' => $_POST['wp_rp_date_option']
|
282 |
-
);
|
283 |
-
|
284 |
-
if ($wp_rp_saved != $wp_rp)
|
285 |
-
if(!update_option("wp_rp",$wp_rp))
|
286 |
-
$message = "Update Failed";
|
287 |
-
|
288 |
-
echo '<div id="message" class="updated fade"><p>'.$message.'.</p></div>';
|
289 |
-
}
|
290 |
-
|
291 |
-
$wp_rp = get_option("wp_rp");
|
292 |
-
?>
|
293 |
-
<div class="wrap">
|
294 |
-
<h2 id="write-post"><?php _e("Related Posts Options…",'wp_related_posts');?></h2>
|
295 |
-
<p><?php _e("WordPress Related Posts Plugin will generate a related posts via WordPress tags, and add the related posts to feed.",'wp_related_posts');?></p>
|
296 |
-
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>?page=<?php echo basename(__FILE__); ?>">
|
297 |
-
<h3><?php _e("Related Posts Preference",'wp_related_posts');?></h3>
|
298 |
-
<table class="form-table">
|
299 |
-
<tr>
|
300 |
-
<th><?php _e("Related Posts Title:",'wp_related_posts'); ?></th>
|
301 |
-
<td>
|
302 |
-
<input type="text" name="wp_rp_title_option" value="<?php echo $wp_rp["wp_rp_title"]; ?>" />
|
303 |
-
</td>
|
304 |
-
</tr>
|
305 |
-
<tr>
|
306 |
-
<th><?php _e("When No Related Posts, Dispaly:",'wp_related_posts'); ?></th>
|
307 |
-
<td>
|
308 |
-
<?php $wp_no_rp = $wp_rp["wp_no_rp"]; ?>
|
309 |
-
<select name="wp_no_rp_option" >
|
310 |
-
<option value="text" <?php if($wp_no_rp == 'text') echo 'selected' ?> ><?php _e("Text: 'No Related Posts'",'wp_related_posts'); ?></option>
|
311 |
-
<option value="random" <?php if($wp_no_rp == 'random') echo 'selected' ?>><?php _e("Random Posts",'wp_related_posts'); ?></option>
|
312 |
-
<option value="commented" <?php if($wp_no_rp == 'commented') echo 'selected' ?>><?php _e("Most Commented Posts",'wp_related_posts'); ?></option>
|
313 |
-
<?php if (function_exists('akpc_most_popular')){ ?>
|
314 |
-
<option value="popularity" <?php if($wp_no_rp == 'popularity') echo 'selected' ?>><?php _e("Most Popular Posts",'wp_related_posts'); ?></option>
|
315 |
-
<?php } ?>
|
316 |
-
</select>
|
317 |
-
</td>
|
318 |
-
</tr>
|
319 |
-
<tr>
|
320 |
-
<th><?php _e("No Related Post's Title or Text:",'wp_related_posts'); ?></th>
|
321 |
-
<td>
|
322 |
-
<input type="text" name="wp_no_rp_text_option" value="<?php echo $wp_rp["wp_no_rp_text"]; ?>" />
|
323 |
-
</td>
|
324 |
-
</tr>
|
325 |
-
<tr>
|
326 |
-
<th><?php _e("Limit:",'wp_related_posts');?></th>
|
327 |
-
<td>
|
328 |
-
<input type="text" name="wp_rp_limit_option" value="<?php echo $wp_rp["wp_rp_limit"]; ?>" />
|
329 |
-
</td>
|
330 |
-
</tr>
|
331 |
-
<tr>
|
332 |
-
<th><?php _e("Exclude(category IDs):",'wp_related_posts');?></th>
|
333 |
-
<td>
|
334 |
-
<input type="text" name="wp_rp_exclude_option" value="<?php echo $wp_rp["wp_rp_exclude"]; ?>" />
|
335 |
-
</td>
|
336 |
-
</tr>
|
337 |
-
<tr>
|
338 |
-
<th><?php _e("Other Setting:",'wp_related_posts');?></th>
|
339 |
-
<td>
|
340 |
-
<label>
|
341 |
-
<?php
|
342 |
-
if ( $wp_rp["wp_rp_auto"] == 'yes' ) {
|
343 |
-
echo '<input name="wp_rp_auto_option" type="checkbox" value="yes" checked>';
|
344 |
-
} else {
|
345 |
-
echo '<input name="wp_rp_auto_option" type="checkbox" value="yes">';
|
346 |
-
}
|
347 |
-
?>
|
348 |
-
<?php _e("Auto Insert Related Posts",'wp_related_posts');?>
|
349 |
-
</label>
|
350 |
-
<br />
|
351 |
-
<label>
|
352 |
-
<?php
|
353 |
-
if ( $wp_rp["wp_rp_rss"] == 'yes' ) {
|
354 |
-
echo '<input name="wp_rp_rss_option" type="checkbox" value="yes" checked>';
|
355 |
-
} else {
|
356 |
-
echo '<input name="wp_rp_rss_option" type="checkbox" value="yes">';
|
357 |
-
}
|
358 |
-
?>
|
359 |
-
<?php _e("Related Posts for RSS",'wp_related_posts');?>
|
360 |
-
</label>
|
361 |
-
<br />
|
362 |
-
<label>
|
363 |
-
<?php
|
364 |
-
if ( $wp_rp["wp_rp_comments"] == 'yes' ) {
|
365 |
-
echo '<input name="wp_rp_comments_option" type="checkbox" value="yes" checked>';
|
366 |
-
} else {
|
367 |
-
echo '<input name="wp_rp_comments_option" type="checkbox" value="yes">';
|
368 |
-
}
|
369 |
-
?>
|
370 |
-
<?php _e("Display Comments Count",'wp_related_posts');?>
|
371 |
-
</label>
|
372 |
-
<br />
|
373 |
-
<label>
|
374 |
-
<?php
|
375 |
-
if ( $wp_rp["wp_rp_date"] == 'yes' ) {
|
376 |
-
echo '<input name="wp_rp_date_option" type="checkbox" value="yes" checked>';
|
377 |
-
} else {
|
378 |
-
echo '<input name="wp_rp_date_option" type="checkbox" value="yes">';
|
379 |
-
}
|
380 |
-
?>
|
381 |
-
<?php _e("Display Post Date",'wp_related_posts');?>
|
382 |
-
</label>
|
383 |
-
<br />
|
384 |
-
</td>
|
385 |
-
</tr>
|
386 |
-
</table>
|
387 |
-
|
388 |
-
<p class="submit"><input type="submit" value="<?php _e("Update Preferences »",'wp_related_posts');?>" name="wp_rp_Submit" /></p>
|
389 |
-
</form>
|
390 |
-
</div>
|
391 |
-
<?php }?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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/default.po
RENAMED
File without changes
|
{WPRP/lang → lang}/wp_related_posts-zh_CN.mo
RENAMED
Binary file
|
{WPRP/lang → lang}/wp_related_posts-zh_CN.po
RENAMED
@@ -3,7 +3,7 @@ msgstr ""
|
|
3 |
"Project-Id-Version: WordPress 2.3 Related Posts Plugin v0.2\n"
|
4 |
"Report-Msgid-Bugs-To: \n"
|
5 |
"POT-Creation-Date: 2009-09-29 17:04+0800\n"
|
6 |
-
"PO-Revision-Date: 2009-09-29 17:
|
7 |
"Last-Translator: Denis <honghua.deng@gmail.com>\n"
|
8 |
"Language-Team: WordPress 中文团队 <team@wp-cn.com>\n"
|
9 |
"MIME-Version: 1.0\n"
|
3 |
"Project-Id-Version: WordPress 2.3 Related Posts Plugin v0.2\n"
|
4 |
"Report-Msgid-Bugs-To: \n"
|
5 |
"POT-Creation-Date: 2009-09-29 17:04+0800\n"
|
6 |
+
"PO-Revision-Date: 2009-09-29 17:28+0800\n"
|
7 |
"Last-Translator: Denis <honghua.deng@gmail.com>\n"
|
8 |
"Language-Team: WordPress 中文团队 <team@wp-cn.com>\n"
|
9 |
"MIME-Version: 1.0\n"
|
readme.txt
CHANGED
@@ -1,18 +1,18 @@
|
|
1 |
=== Plugin Name ===
|
2 |
Contributors: denishua
|
3 |
Tags: Related,Posts
|
4 |
-
Donate link:
|
5 |
Requires at least: 2.3
|
6 |
-
Tested up to: 2.
|
7 |
-
Stable tag:
|
8 |
|
9 |
WordPress Related Posts Plugin will generate a related posts via WordPress tags, and add the related posts to feed.
|
10 |
|
11 |
== Description ==
|
12 |
|
13 |
WordPress Related Posts Plugin will generate a related posts via WordPress tags, and add the related posts to feed.
|
14 |
-
What would you like to be displayed when there is no related posts, "no related post" or "n" random posts, or anything else, please leave a comment in the plugin page. Thanks in advance!
|
15 |
|
|
|
16 |
|
17 |
== Installation ==
|
18 |
|
@@ -22,14 +22,15 @@ What would you like to be displayed when there is no related posts, "no related
|
|
22 |
1. Navigate to Manage > Option > WordPress Related Posts to configure plugin output.
|
23 |
|
24 |
== Screenshots ==
|
|
|
25 |
|
26 |
-
1. WordPress Related Posts Plugin Option Setting.
|
27 |
|
|
|
28 |
|
29 |
-
|
|
|
|
|
|
|
30 |
|
31 |
-
1.
|
32 |
-
|
33 |
-
1. Activate the plugin through the 'Plugins' menu in WordPress
|
34 |
-
1. Place `<?php wp_related_posts(); ?>` in your templates
|
35 |
-
1. Navigate to Manage > Option > WordPress Related Posts to configure plugin output.
|
1 |
=== Plugin Name ===
|
2 |
Contributors: denishua
|
3 |
Tags: Related,Posts
|
4 |
+
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=8490579
|
5 |
Requires at least: 2.3
|
6 |
+
Tested up to: 2.8.4
|
7 |
+
Stable tag: 1.1
|
8 |
|
9 |
WordPress Related Posts Plugin will generate a related posts via WordPress tags, and add the related posts to feed.
|
10 |
|
11 |
== Description ==
|
12 |
|
13 |
WordPress Related Posts Plugin will generate a related posts via WordPress tags, and add the related posts to feed.
|
|
|
14 |
|
15 |
+
Please search and submit your transaltion here: <a href="http://fairyfish.net/2008/06/06/wordpress-related-posts-plugin-translation/">http://fairyfish.net/2008/06/06/wordpress-related-posts-plugin-translation/</a>
|
16 |
|
17 |
== Installation ==
|
18 |
|
22 |
1. Navigate to Manage > Option > WordPress Related Posts to configure plugin output.
|
23 |
|
24 |
== Screenshots ==
|
25 |
+
1. WordPress Related Posts setting.
|
26 |
|
|
|
27 |
|
28 |
+
== Changelog ==
|
29 |
|
30 |
+
= 1.1 =
|
31 |
+
* Post Except
|
32 |
+
* Thumbnail
|
33 |
+
* Widget
|
34 |
|
35 |
+
= 1.0 =
|
36 |
+
* first version
|
|
|
|
|
|
screenshot-1.jpg
ADDED
Binary file
|
screenshot-1.png
DELETED
Binary file
|
wp_related_posts.php
ADDED
@@ -0,0 +1,502 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
6 |
+
Description: Generate a related posts list via tags of WordPress
|
7 |
+
Author: Denis
|
8 |
+
Author URI: http://fairyfish.net/
|
9 |
+
*/
|
10 |
+
|
11 |
+
add_action('init', 'init_textdomain');
|
12 |
+
function init_textdomain(){
|
13 |
+
load_plugin_textdomain('wp_related_posts',PLUGINDIR . '/' . dirname(plugin_basename (__FILE__)) . '/lang');
|
14 |
+
}
|
15 |
+
|
16 |
+
function wp_get_related_posts($before_title="",$after_title="") {
|
17 |
+
if(!is_single()) return;
|
18 |
+
|
19 |
+
global $wpdb, $post,$table_prefix;
|
20 |
+
$wp_rp = get_option("wp_rp");
|
21 |
+
|
22 |
+
$wp_rp_title = $wp_rp["wp_rp_title"];
|
23 |
+
|
24 |
+
$exclude = explode(",",$wp_rp["wp_rp_exclude"]);
|
25 |
+
if ( $exclude != '' ) {
|
26 |
+
$q = 'SELECT tt.term_id FROM '. $table_prefix .'term_taxonomy tt, ' . $table_prefix . 'term_relationships tr WHERE tt.taxonomy = \'category\' AND tt.term_taxonomy_id = tr.term_taxonomy_id AND tr.object_id = '.$post->ID;
|
27 |
+
|
28 |
+
$cats = $wpdb->get_results($q);
|
29 |
+
|
30 |
+
foreach(($cats) as $cat) {
|
31 |
+
if (in_array($cat->term_id, $exclude) != false){
|
32 |
+
return;
|
33 |
+
}
|
34 |
+
}
|
35 |
+
}
|
36 |
+
|
37 |
+
if(!$post->ID){return;}
|
38 |
+
$now = current_time('mysql', 1);
|
39 |
+
$tags = wp_get_post_tags($post->ID);
|
40 |
+
|
41 |
+
$taglist = "'" . $tags[0]->term_id. "'";
|
42 |
+
|
43 |
+
$tagcount = count($tags);
|
44 |
+
if ($tagcount > 1) {
|
45 |
+
for ($i = 1; $i <= $tagcount; $i++) {
|
46 |
+
$taglist = $taglist . ", '" . $tags[$i]->term_id . "'";
|
47 |
+
}
|
48 |
+
}
|
49 |
+
|
50 |
+
$limit = $wp_rp["wp_rp_limit"];
|
51 |
+
if ($limit) {
|
52 |
+
$limitclause = "LIMIT $limit";
|
53 |
+
} else {
|
54 |
+
$limitclause = "LIMIT 10";
|
55 |
+
}
|
56 |
+
|
57 |
+
$q = "SELECT p.ID, p.post_title, p.post_content,p.post_excerpt, p.post_date, p.comment_count, count(t_r.object_id) as cnt FROM $wpdb->term_taxonomy t_t, $wpdb->term_relationships t_r, $wpdb->posts p WHERE t_t.taxonomy ='post_tag' AND t_t.term_taxonomy_id = t_r.term_taxonomy_id AND t_r.object_id = p.ID AND (t_t.term_id IN ($taglist)) AND p.ID != $post->ID AND p.post_status = 'publish' AND p.post_date_gmt < '$now' GROUP BY t_r.object_id ORDER BY cnt DESC, p.post_date_gmt DESC $limitclause;";
|
58 |
+
|
59 |
+
$related_posts = $wpdb->get_results($q);
|
60 |
+
|
61 |
+
$output = "";
|
62 |
+
|
63 |
+
if (!$related_posts){
|
64 |
+
$wp_no_rp = $wp_rp["wp_no_rp"];
|
65 |
+
$wp_no_rp_text = $wp_rp["wp_no_rp_text"];
|
66 |
+
|
67 |
+
if(!$wp_no_rp || ($wp_no_rp == "popularity" && !function_exists('akpc_most_popular'))) $wp_no_rp = "text";
|
68 |
+
|
69 |
+
if($wp_no_rp == "text"){
|
70 |
+
if(!$wp_no_rp_text) $wp_no_rp_text= __("No Related Post",'wp_related_posts');
|
71 |
+
$output .= '<li>'.$wp_no_rp_text .'</li>';
|
72 |
+
} else{
|
73 |
+
if($wp_no_rp == "random"){
|
74 |
+
if(!$wp_no_rp_text) $wp_no_rp_text= __("Random Posts",'wp_related_posts');
|
75 |
+
$related_posts = wp_get_random_posts($limitclause);
|
76 |
+
} elseif($wp_no_rp == "commented"){
|
77 |
+
if(!$wp_no_rp_text) $wp_no_rp_text= __("Most Commented Posts",'wp_related_posts');
|
78 |
+
$related_posts = wp_get_most_commented_posts($limitclause);
|
79 |
+
} elseif($wp_no_rp == "popularity"){
|
80 |
+
if(!$wp_no_rp_text) $wp_no_rp_text= __("Most Popular Posts",'wp_related_posts');
|
81 |
+
$related_posts = wp_get_most_popular_posts($limitclause);
|
82 |
+
}
|
83 |
+
$wp_rp_title = $wp_no_rp_text;
|
84 |
+
}
|
85 |
+
}
|
86 |
+
|
87 |
+
foreach ($related_posts as $related_post ){
|
88 |
+
$output .= '<li>';
|
89 |
+
|
90 |
+
if ($wp_rp["wp_rp_thumbnail"]){
|
91 |
+
$output .= '<a href="'.get_permalink($related_post->ID).'" title="'.wptexturize($related_post->post_title).'"><img src="'.get_post_meta($related_post->ID, $wp_rp["wp_rp_thumbnail_post_meta"], true).'" alt="'.wptexturize($related_post->post_title).'" /></a>';
|
92 |
+
}
|
93 |
+
|
94 |
+
if ((!$wp_rp["wp_rp_thumbnail"])||($wp_rp["wp_rp_thumbnail"] && $wp_rp["wp_rp_thumbnail_text"])){
|
95 |
+
|
96 |
+
if ($wp_rp["wp_rp_date"]){
|
97 |
+
$dateformat = get_option('date_format');
|
98 |
+
$output .= mysql2date($dateformat, $related_post->post_date) . " -- ";
|
99 |
+
}
|
100 |
+
|
101 |
+
$output .= '<a href="'.get_permalink($related_post->ID).'" title="'.wptexturize($related_post->post_title).'">'.wptexturize($related_post->post_title).'</a>';
|
102 |
+
|
103 |
+
if ($wp_rp["wp_rp_comments"]){
|
104 |
+
$output .= " (" . $related_post->comment_count . ")";
|
105 |
+
}
|
106 |
+
|
107 |
+
if ($wp_rp["wp_rp_except"]){
|
108 |
+
$wp_rp_except_number = trim($wp_rp["wp_rp_except_number"]);
|
109 |
+
if(!$wp_rp_except_number) $wp_rp_except_number = 200;
|
110 |
+
if($related_post->post_excerpt){
|
111 |
+
$output .= '<br /><small>'.(mb_substr(strip_tags($related_post->post_excerpt),0,$wp_rp_except_number)).'...</small>';
|
112 |
+
}else{
|
113 |
+
$output .= '<br /><small>'.(mb_substr(strip_tags($related_post->post_content),0,$wp_rp_except_number)).'...</small>';
|
114 |
+
}
|
115 |
+
}
|
116 |
+
}
|
117 |
+
$output .= '</li>';
|
118 |
+
}
|
119 |
+
|
120 |
+
$output = '<ul>' . $output . '</ul>';
|
121 |
+
|
122 |
+
$wp_rp_title_tag = $wp_rp["wp_rp_title_tag"];
|
123 |
+
if($before_title){
|
124 |
+
if($wp_rp_title != '') $output = $before_title.$wp_rp_title .$after_title. $output;
|
125 |
+
}else{
|
126 |
+
if(!$wp_rp_title_tag) $wp_rp_title_tag ='h3';
|
127 |
+
if($wp_rp_title != '') $output = '<'.$wp_rp_title_tag.'>'.$wp_rp_title .'</'.$wp_rp_title_tag.'>'. $output;
|
128 |
+
}
|
129 |
+
|
130 |
+
$output ='<div class="related_post">'.$output.'</div>';
|
131 |
+
return $output;
|
132 |
+
}
|
133 |
+
|
134 |
+
function wp_related_posts(){
|
135 |
+
|
136 |
+
$output = wp_get_related_posts() ;
|
137 |
+
|
138 |
+
echo $output;
|
139 |
+
}
|
140 |
+
|
141 |
+
function wp23_related_posts() {
|
142 |
+
wp_related_posts();
|
143 |
+
}
|
144 |
+
|
145 |
+
function wp_related_posts_for_feed($content=""){
|
146 |
+
$wp_rp = get_option("wp_rp");
|
147 |
+
if(is_feed() && $wp_rp["wp_rp_rss"] == 'yes'){
|
148 |
+
$output = wp_get_related_posts();
|
149 |
+
$content = $content . $output;
|
150 |
+
}
|
151 |
+
return $content;
|
152 |
+
}
|
153 |
+
|
154 |
+
add_filter('the_content', 'wp_related_posts_for_feed',1);
|
155 |
+
|
156 |
+
function wp_related_posts_auto($content=""){
|
157 |
+
$wp_rp = get_option("wp_rp");
|
158 |
+
if ( (is_single()) && $wp_rp["wp_rp_auto"]) {
|
159 |
+
$output = wp_get_related_posts();
|
160 |
+
$content = $content . $output;
|
161 |
+
}
|
162 |
+
|
163 |
+
return $content;
|
164 |
+
}
|
165 |
+
|
166 |
+
add_filter('the_content', 'wp_related_posts_auto',99);
|
167 |
+
|
168 |
+
function wp_get_random_posts ($limitclause="") {
|
169 |
+
global $wpdb, $tableposts, $post;
|
170 |
+
|
171 |
+
$q = "SELECT ID, post_title, post_content,post_excerpt, post_date, comment_count FROM $tableposts WHERE post_status = 'publish' AND post_type = 'post' AND ID != $post->ID ORDER BY RAND() $limitclause";
|
172 |
+
return $wpdb->get_results($q);
|
173 |
+
}
|
174 |
+
|
175 |
+
function wp_random_posts ($number = 10){
|
176 |
+
$limitclause="LIMIT " . $number;
|
177 |
+
$random_posts = wp_get_random_posts ($limitclause);
|
178 |
+
|
179 |
+
foreach ($random_posts as $random_post ){
|
180 |
+
$output .= '<li>';
|
181 |
+
|
182 |
+
$output .= '<a href="'.get_permalink($random_post->ID).'" title="'.wptexturize($random_post->post_title).'">'.wptexturize($random_post->post_title).'</a></li>';
|
183 |
+
}
|
184 |
+
|
185 |
+
$output = '<ul class="randome_post">' . $output . '</ul>';
|
186 |
+
|
187 |
+
echo $output;
|
188 |
+
}
|
189 |
+
|
190 |
+
function wp_get_most_commented_posts($limitclause="") {
|
191 |
+
global $wpdb;
|
192 |
+
$q = "SELECT ID, post_title, post_content, post_excerpt, post_date, COUNT($wpdb->comments.comment_post_ID) AS 'comment_count' FROM $wpdb->posts, $wpdb->comments WHERE comment_approved = '1' AND $wpdb->posts.ID=$wpdb->comments.comment_post_ID AND post_status = 'publish' GROUP BY $wpdb->comments.comment_post_ID ORDER BY comment_count DESC $limitclause";
|
193 |
+
return $wpdb->get_results($q);
|
194 |
+
}
|
195 |
+
|
196 |
+
function wp_most_commented_posts ($number = 10){
|
197 |
+
$limitclause="LIMIT " . $number;
|
198 |
+
$most_commented_posts = wp_get_most_commented_posts ($limitclause);
|
199 |
+
|
200 |
+
foreach ($most_commented_posts as $most_commented_post ){
|
201 |
+
$output .= '<li>';
|
202 |
+
|
203 |
+
$output .= '<a href="'.get_permalink($most_commented_post->ID).'" title="'.wptexturize($most_commented_post->post_title).'">'.wptexturize($most_commented_post->post_title).'</a></li>';
|
204 |
+
}
|
205 |
+
|
206 |
+
$output = '<ul class="most_commented_post">' . $output . '</ul>';
|
207 |
+
|
208 |
+
echo $output;
|
209 |
+
}
|
210 |
+
|
211 |
+
function wp_get_most_popular_posts ($limitclause="") {
|
212 |
+
global $wpdb, $table_prefix;
|
213 |
+
|
214 |
+
$q = $sql = "SELECT p.ID, p.post_title, p.post_content,p.post_excerpt, p.post_date, p.comment_count FROM ". $table_prefix ."ak_popularity as akpc,".$table_prefix ."posts as p WHERE p.ID = akpc.post_id ORDER BY akpc.total DESC $limitclause";;
|
215 |
+
return $wpdb->get_results($q);
|
216 |
+
}
|
217 |
+
|
218 |
+
function wp_most_popular_posts ($number = 10){
|
219 |
+
$limitclause="LIMIT " . $number;
|
220 |
+
$most_popular_posts = wp_get_most_popular_posts ($limitclause);
|
221 |
+
|
222 |
+
foreach ($most_popular_posts as $most_popular_post ){
|
223 |
+
$output .= '<li>';
|
224 |
+
|
225 |
+
$output .= '<a href="'.get_permalink($most_popular_post->ID).'" title="'.wptexturize($most_popular_post->post_title).'">'.wptexturize($most_popular_post->post_title).'</a></li>';
|
226 |
+
}
|
227 |
+
|
228 |
+
$output = '<ul class="most_popular_post">' . $output . '</ul>';
|
229 |
+
|
230 |
+
echo $output;
|
231 |
+
}
|
232 |
+
|
233 |
+
add_action('plugins_loaded', 'widget_sidebar_wp_related_posts');
|
234 |
+
function widget_sidebar_wp_related_posts() {
|
235 |
+
function widget_wp_related_posts($args) {
|
236 |
+
extract($args);
|
237 |
+
if(!is_single()) return;
|
238 |
+
echo $before_widget;
|
239 |
+
|
240 |
+
//echo $before_title . $wp_rp["wp_rp_title"] . $after_title;
|
241 |
+
$output = wp_get_related_posts($before_title,$after_title);
|
242 |
+
echo $output;
|
243 |
+
echo $after_widget;
|
244 |
+
}
|
245 |
+
register_sidebar_widget('Related Posts', 'widget_wp_related_posts');
|
246 |
+
}
|
247 |
+
|
248 |
+
add_action('admin_menu', 'wp_add_related_posts_options_page');
|
249 |
+
|
250 |
+
function wp_add_related_posts_options_page() {
|
251 |
+
if (function_exists('add_options_page')) {
|
252 |
+
add_options_page( __('Related Posts','wp_related_posts'), __('Related Posts','wp_related_posts'), 8, basename(__FILE__), 'wp_related_posts_options_subpanel');
|
253 |
+
}
|
254 |
+
}
|
255 |
+
|
256 |
+
function wp_related_posts_options_subpanel() {
|
257 |
+
if($_POST["wp_rp_Submit"]){
|
258 |
+
$message = __("WordPress Related Posts Setting Updated",'wp_related_posts');
|
259 |
+
|
260 |
+
$wp_rp_saved = get_option("wp_rp");
|
261 |
+
|
262 |
+
$wp_rp = array (
|
263 |
+
"wp_rp_title" => trim($_POST['wp_rp_title_option']),
|
264 |
+
"wp_rp_title_tag" => trim($_POST['wp_rp_title_tag_option']),
|
265 |
+
"wp_no_rp" => trim($_POST['wp_no_rp_option']),
|
266 |
+
"wp_no_rp_text" => trim($_POST['wp_no_rp_text_option']),
|
267 |
+
"wp_rp_except" => trim($_POST['wp_rp_except_option']),
|
268 |
+
"wp_rp_except_number" => trim($_POST['wp_rp_except_number_option']),
|
269 |
+
"wp_rp_limit" => trim($_POST['wp_rp_limit_option']),
|
270 |
+
'wp_rp_exclude' => trim($_POST['wp_rp_exclude_option']),
|
271 |
+
'wp_rp_auto' => trim($_POST['wp_rp_auto_option']),
|
272 |
+
'wp_rp_rss' => trim($_POST['wp_rp_rss_option']),
|
273 |
+
'wp_rp_comments' => trim($_POST['wp_rp_comments_option']),
|
274 |
+
'wp_rp_date' => trim($_POST['wp_rp_date_option']),
|
275 |
+
'wp_rp_thumbnail' => trim($_POST['wp_rp_thumbnail_option']),
|
276 |
+
'wp_rp_thumbnail_text' => trim($_POST['wp_rp_thumbnail_text_option']),
|
277 |
+
'wp_rp_thumbnail_post_meta' => trim($_POST['wp_rp_thumbnail_post_meta_option'])
|
278 |
+
);
|
279 |
+
|
280 |
+
if ($wp_rp_saved != $wp_rp)
|
281 |
+
if(!update_option("wp_rp",$wp_rp))
|
282 |
+
$message = "Update Failed";
|
283 |
+
|
284 |
+
echo '<div id="message" class="updated fade"><p>'.$message.'.</p></div>';
|
285 |
+
}
|
286 |
+
|
287 |
+
$wp_rp = get_option("wp_rp");
|
288 |
+
?>
|
289 |
+
<div class="wrap">
|
290 |
+
<?php
|
291 |
+
$wp_no_rp = $wp_rp["wp_no_rp"];
|
292 |
+
$wp_rp_title_tag = $wp_rp["wp_rp_title_tag"];
|
293 |
+
?>
|
294 |
+
<script type='text/javascript'>
|
295 |
+
function wp_no_rp_onchange(){
|
296 |
+
var wp_no_rp = document.getElementById('wp_no_rp');
|
297 |
+
var wp_no_rp_title = document.getElementById('wp_no_rp_title');
|
298 |
+
var wp_no_rp_text = document.getElementById('wp_no_rp_text');
|
299 |
+
switch(wp_no_rp.value){
|
300 |
+
case 'text':
|
301 |
+
wp_no_rp_title.innerHTML = '<?php _e("No Related Posts Text:",'wp_related_posts'); ?>';
|
302 |
+
wp_no_rp_text.value = '<?php _e("No Related Posts",'wp_related_posts'); ?>';
|
303 |
+
break;
|
304 |
+
case 'random':
|
305 |
+
wp_no_rp_title.innerHTML = '<?php _e("Random Posts Title:",'wp_related_posts'); ?>';
|
306 |
+
wp_no_rp_text.value = '<?php _e("Random Posts",'wp_related_posts'); ?>';
|
307 |
+
break;
|
308 |
+
case 'commented':
|
309 |
+
wp_no_rp_title.innerHTML = '<?php _e("Most Commented Posts Title:",'wp_related_posts'); ?>';
|
310 |
+
wp_no_rp_text.value = '<?php _e("Most Commented Posts",'wp_related_posts'); ?>';
|
311 |
+
break;
|
312 |
+
case 'popularity':
|
313 |
+
wp_no_rp_title.innerHTML = '<?php _e("Most Popular Posts Title:",'wp_related_posts'); ?>';
|
314 |
+
wp_no_rp_text.value = '<?php _e("Most Popular Posts",'wp_related_posts'); ?>';
|
315 |
+
break;
|
316 |
+
default:
|
317 |
+
wp_no_rp_title.innerHTML = '';
|
318 |
+
}
|
319 |
+
if(wp_no_rp.value == '<?php echo $wp_no_rp;?>'){
|
320 |
+
wp_no_rp_text.value = '<?php echo $wp_rp["wp_no_rp_text"];?>';
|
321 |
+
}
|
322 |
+
}
|
323 |
+
function wp_rp_except_onclick(){
|
324 |
+
var wp_rp_except = document.getElementById('wp_rp_except');
|
325 |
+
var wp_rp_except_number_label = document.getElementById('wp_rp_except_number_label');
|
326 |
+
if(wp_rp_except.checked){
|
327 |
+
wp_rp_except_number_label.style.display = '';
|
328 |
+
} else {
|
329 |
+
wp_rp_except_number_label.style.display = 'none';
|
330 |
+
}
|
331 |
+
}
|
332 |
+
function wp_rp_thumbnail_onclick(){
|
333 |
+
var wp_rp_thumbnail = document.getElementById('wp_rp_thumbnail');
|
334 |
+
var wp_rp_thumbnail_span = document.getElementById('wp_rp_thumbnail_span');
|
335 |
+
if(wp_rp_thumbnail.checked){
|
336 |
+
wp_rp_thumbnail_span.style.display = '';
|
337 |
+
} else {
|
338 |
+
wp_rp_thumbnail_span.style.display = 'none';
|
339 |
+
}
|
340 |
+
}
|
341 |
+
</script>
|
342 |
+
|
343 |
+
<h2><?php _e("Related Posts Settings",'wp_related_posts');?></h2>
|
344 |
+
<p><?php _e("<a href=\"http://fairyfish.net/2007/09/12/wordpress-23-related-posts-plugin/\">WordPress Related Posts </a>Plugin can generate a related posts list via WordPress tags, and add the related posts to feed.",'wp_related_posts');?> </p>
|
345 |
+
<?php _e("Any problem or need help, please contact ",'wp_related_posts');?><a href="mailto:denishua@hotmail.com">denishua</a>.</p>
|
346 |
+
|
347 |
+
<div>
|
348 |
+
<span style="font-size:16px; height:30px; line-height:30px; padding:0 10px;"> <a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=8490579"><?php _e("Do you like this Plugin? Consider to donate!",'wp_related_posts');?></a></span> <a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=8490579"><img src="https://www.paypal.com/en_GB/i/btn/btn_donate_LG.gif" align="left" /></a>
|
349 |
+
</div>
|
350 |
+
|
351 |
+
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>?page=<?php echo basename(__FILE__); ?>">
|
352 |
+
<h3><?php _e("Basic Setting",'wp_related_posts');?></h3>
|
353 |
+
<table class="form-table">
|
354 |
+
<tr valign="top">
|
355 |
+
<th scope="row"><label for="wp_rp_title"><?php _e("Related Posts Title:",'wp_related_posts'); ?></label></th>
|
356 |
+
<td>
|
357 |
+
<input name="wp_rp_title_option" type="text" id="wp_rp_title" value="<?php echo $wp_rp["wp_rp_title"]; ?>" class="regular-text" />
|
358 |
+
</td>
|
359 |
+
</tr>
|
360 |
+
<tr valign="top">
|
361 |
+
<th scope="row"><label for="wp_rp_title_tag"><?php _e("Related Posts Title Tag:",'wp_related_posts'); ?></label></th>
|
362 |
+
<td>
|
363 |
+
<select name="wp_rp_title_tag_option" id="wp_rp_title_tag" class="postform">
|
364 |
+
<?php
|
365 |
+
$wp_rp_title_tag_array = array('h2','h3','h4','p','div');
|
366 |
+
foreach ($wp_rp_title_tag_array as $wp_rp_title_tag_a){
|
367 |
+
?>
|
368 |
+
<option value="<?php echo $wp_rp_title_tag_a; ?>" <?php if($wp_rp_title_tag == $wp_rp_title_tag_a) echo 'selected' ?> ><<?php echo $wp_rp_title_tag_a; ?>></option>
|
369 |
+
<?php
|
370 |
+
}
|
371 |
+
?>
|
372 |
+
</select>
|
373 |
+
</td>
|
374 |
+
</tr>
|
375 |
+
<tr valign="top">
|
376 |
+
<th scope="row"><label for="wp_rp_limit"><?php _e("Maximum Number:",'wp_related_posts');?></label></th>
|
377 |
+
<td>
|
378 |
+
<input name="wp_rp_limit_option" type="text" id="wp_rp_limit" value="<?php echo $wp_rp["wp_rp_limit"]; ?>" />
|
379 |
+
</td>
|
380 |
+
</tr>
|
381 |
+
<tr valign="top">
|
382 |
+
<th scope="row"><label for="wp_rp_exclude"><?php _e("Exclude(category IDs):",'wp_related_posts');?></label></th>
|
383 |
+
<td>
|
384 |
+
<input name="wp_rp_exclude_option" type="text" id="wp_rp_exclude" value="<?php echo $wp_rp["wp_rp_exclude"]; ?>" /> <span class="description"><?php _e('Enter category IDs of the posts which you don\'t want to display related posts for them. ','wp_related_posts'); ?></span>
|
385 |
+
</td>
|
386 |
+
</tr>
|
387 |
+
<tr valign="top">
|
388 |
+
<th scope="row"><?php _e("Other Setting:",'wp_related_posts'); ?></th>
|
389 |
+
<td>
|
390 |
+
<label>
|
391 |
+
<input name="wp_rp_comments_option" type="checkbox" id="wp_rp_comments" value="yes" <?php echo ($wp_rp["wp_rp_comments"] == 'yes') ? 'checked' : ''; ?>>
|
392 |
+
<?php _e("Display Comments Count?",'wp_related_posts');?>
|
393 |
+
</label>
|
394 |
+
<br />
|
395 |
+
<label>
|
396 |
+
<input name="wp_rp_date_option" type="checkbox" id="wp_rp_date" value="yes" <?php echo ($wp_rp["wp_rp_date"] == 'yes') ? 'checked' : ''; ?>>
|
397 |
+
<?php _e("Display Pubilsh Date?",'wp_related_posts');?>
|
398 |
+
</label>
|
399 |
+
<br />
|
400 |
+
<label>
|
401 |
+
<input name="wp_rp_auto_option" type="checkbox" id="wp_rp_auto" value="yes" <?php echo ($wp_rp["wp_rp_auto"] == 'yes') ? 'checked' : ''; ?>>
|
402 |
+
<?php _e("Auto Insert Related Posts?",'wp_related_posts');?>
|
403 |
+
</label>
|
404 |
+
<br />
|
405 |
+
<label>
|
406 |
+
<input name="wp_rp_rss_option" type="checkbox" id="wp_rp_rss" value="yes" <?php echo ($wp_rp["wp_rp_rss"] == 'yes') ? 'checked' : ''; ?>>
|
407 |
+
<?php _e("Display Related Posts on Feed?",'wp_related_posts');?>
|
408 |
+
</label>
|
409 |
+
</td>
|
410 |
+
</tr>
|
411 |
+
<tr valign="top">
|
412 |
+
<th scope="row"><label for="wp_rp_except"><?php _e("Except Setting:",'wp_related_posts'); ?></label></th>
|
413 |
+
<td>
|
414 |
+
<label>
|
415 |
+
<input name="wp_rp_except_option" type="checkbox" id="wp_rp_except" value="yes" <?php echo ($wp_rp["wp_rp_except"] == 'yes') ? 'checked' : ''; ?> onclick="wp_rp_except_onclick();" >
|
416 |
+
<?php _e("Display Post Except?",'wp_related_posts');?>
|
417 |
+
</label>
|
418 |
+
<br />
|
419 |
+
<label id="wp_rp_except_number_label" style="<?php echo ($wp_rp["wp_rp_except"] == 'yes') ? '' : 'display:none;'; ?>">
|
420 |
+
<input name="wp_rp_except_number_option" type="text" id="wp_rp_except_number" value="<?php echo ($wp_rp["wp_rp_except_number"]); ?> " /> <span class="description"><?php _e('Maximum Charaters of Except.','wp_related_posts'); ?></span>
|
421 |
+
</label>
|
422 |
+
</td>
|
423 |
+
</tr>
|
424 |
+
</table>
|
425 |
+
<h3><?php _e("No Related Post Setting",'wp_related_posts');?></h3>
|
426 |
+
<table class="form-table">
|
427 |
+
<tr valign="top">
|
428 |
+
<th scope="row"><label for="wp_no_rp"><?php _e("Display:",'wp_related_posts'); ?></label></th>
|
429 |
+
<td>
|
430 |
+
<select name="wp_no_rp_option" id="wp_no_rp" onchange="wp_no_rp_onchange();" class="postform">
|
431 |
+
<option value="text" <?php if($wp_no_rp == 'text') echo 'selected' ?> ><?php _e("Text: 'No Related Posts'",'wp_related_posts'); ?></option>
|
432 |
+
<option value="random" <?php if($wp_no_rp == 'random') echo 'selected' ?>><?php _e("Random Posts",'wp_related_posts'); ?></option>
|
433 |
+
<option value="commented" <?php if($wp_no_rp == 'commented') echo 'selected' ?>><?php _e("Most Commented Posts",'wp_related_posts'); ?></option>
|
434 |
+
<?php if (function_exists('akpc_most_popular')){ ?>
|
435 |
+
<option value="popularity" <?php if($wp_no_rp == 'popularity') echo 'selected' ?>><?php _e("Most Popular Posts",'wp_related_posts'); ?></option>
|
436 |
+
<?php } ?>
|
437 |
+
</select>
|
438 |
+
</td>
|
439 |
+
</tr>
|
440 |
+
<tr valign="top" scope="row">
|
441 |
+
<th id="wp_no_rp_title" scope="row"><label for="wp_no_rp_text">
|
442 |
+
<?php
|
443 |
+
switch ($wp_no_rp){
|
444 |
+
case 'text':
|
445 |
+
_e("No Related Posts Text:",'wp_related_posts');
|
446 |
+
break;
|
447 |
+
case 'random':
|
448 |
+
_e("Random Posts Title:",'wp_related_posts');
|
449 |
+
break;
|
450 |
+
case 'commented':
|
451 |
+
_e("Most Commented Posts Title:",'wp_related_posts');
|
452 |
+
break;
|
453 |
+
case 'popularity':
|
454 |
+
_e("Most Popular Posts Title:",'wp_related_posts');
|
455 |
+
break;
|
456 |
+
}
|
457 |
+
?>
|
458 |
+
</label></th>
|
459 |
+
<td>
|
460 |
+
<input name="wp_no_rp_text_option" type="text" id="wp_no_rp_text" value="<?php echo $wp_rp["wp_no_rp_text"]; ?>" class="regular-text" />
|
461 |
+
</td>
|
462 |
+
</tr>
|
463 |
+
</table>
|
464 |
+
<h3><?php _e("Related Posts with Thumbnail",'wp_related_posts');?></h3>
|
465 |
+
<table class="form-table">
|
466 |
+
<tr valign="top">
|
467 |
+
<th colspan="2">
|
468 |
+
<?php _e("Befor usting Related Posts with Thumbnail, you must set thumbnail image for your every post.",'wp_related_posts'); ?>
|
469 |
+
</th>
|
470 |
+
</tr>
|
471 |
+
<tr valign="top">
|
472 |
+
<th scope="row"><label for="wp_rp_thumbnail"><?php _e("Thumbnail Setting:",'wp_related_posts'); ?></label></th>
|
473 |
+
<td>
|
474 |
+
<input name="wp_rp_thumbnail_option" type="checkbox" id="wp_rp_thumbnail" value="yes" <?php echo ($wp_rp["wp_rp_thumbnail"] == 'yes') ? 'checked' : ''; ?> onclick="wp_rp_thumbnail_onclick();" >
|
475 |
+
<?php _e("Display Thumbnails For Related Posts?",'wp_related_posts');?>
|
476 |
+
<br />
|
477 |
+
<span id="wp_rp_thumbnail_span" style="<?php echo ($wp_rp["wp_rp_thumbnail"] == 'yes') ? '' : 'display:none;'; ?>">
|
478 |
+
<input name="wp_rp_thumbnail_text_option" type="checkbox" id="wp_rp_thumbnail_text" value="yes" <?php echo ($wp_rp["wp_rp_thumbnail_text"] == 'yes') ? 'checked' : ''; ?>>
|
479 |
+
<?php _e("Do you still want to display text when display thumbnails for related posts?",'wp_related_posts');?>
|
480 |
+
<br />
|
481 |
+
<?php _e("Which custom field is used for thumbnail?",'wp_related_posts');?>
|
482 |
+
<select name="wp_rp_thumbnail_post_meta_option" id="wp_rp_thumbnail_post_meta" class="postform">
|
483 |
+
<?php
|
484 |
+
global $wpdb;
|
485 |
+
$post_metas = $wpdb->get_col( "SELECT meta_key FROM $wpdb->postmeta GROUP BY meta_key HAVING meta_key NOT LIKE '\_%' ORDER BY LOWER(meta_key)" );
|
486 |
+
|
487 |
+
foreach ( $post_metas as $post_meta ) {
|
488 |
+
$post_meta = esc_attr( $post_meta );
|
489 |
+
?>
|
490 |
+
<option value="<?php echo $post_meta; ?>" <?php if($wp_rp["wp_rp_thumbnail_post_meta"] == $post_meta) echo 'selected' ?>><?php echo $post_meta;?> </option>;
|
491 |
+
<?php
|
492 |
+
}
|
493 |
+
?>
|
494 |
+
</select>
|
495 |
+
</span>
|
496 |
+
</td>
|
497 |
+
</tr>
|
498 |
+
</table>
|
499 |
+
<p class="submit"><input type="submit" value="<?php _e("Save changes",'wp_related_posts');?>" name="wp_rp_Submit" class="button-primary" /></p>
|
500 |
+
</form>
|
501 |
+
</div>
|
502 |
+
<?php }?>
|