[wp-cvs] wordpress/wp-includes template-functions-links.php, 1.30,
1.31
Ryan Boren
rboren at users.sourceforge.net
Tue Aug 24 01:36:00 UTC 2004
Update of /cvsroot/cafelog/wordpress/wp-includes
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27583/wp-includes
Modified Files:
template-functions-links.php
Log Message:
Add previous_post_link() and next_post_link().
Index: template-functions-links.php
===================================================================
RCS file: /cvsroot/cafelog/wordpress/wp-includes/template-functions-links.php,v
retrieving revision 1.30
retrieving revision 1.31
diff -C2 -d -r1.30 -r1.31
*** template-functions-links.php 23 Aug 2004 23:28:14 -0000 1.30
--- template-functions-links.php 24 Aug 2004 01:35:57 -0000 1.31
***************
*** 243,246 ****
--- 243,342 ----
// Navigation links
+ function get_previous_post($in_same_cat = false, $excluded_categories = '') {
+ global $post, $wpdb;
+
+ if(! is_single()) {
+ return null;
+ }
+
+ $current_post_date = $post->post_date;
+ $current_category = $post->post_category;
+
+ $sqlcat = '';
+ if ($in_same_cat) {
+ $sqlcat = " AND post_category = '$current_category' ";
+ }
+
+ $sql_exclude_cats = '';
+ if (!empty($excluded_categories)) {
+ $blah = explode('and', $excluded_categories);
+ foreach($blah as $category) {
+ $category = intval($category);
+ $sql_exclude_cats .= " AND post_category != $category";
+ }
+ }
+
+ return @$wpdb->get_row("SELECT ID, post_title FROM $wpdb->posts WHERE post_date < '$current_post_date' AND post_status = 'publish' $sqlcat $sql_exclude_cats ORDER BY post_date DESC LIMIT 1");
+ }
+
+ function get_next_post($in_same_cat = false, $excluded_categories = '') {
+ global $post, $wpdb;
+
+ if(! is_single()) {
+ return null;
+ }
+
+ $current_post_date = $post->post_date;
+ $current_category = $post->post_category;
+
+ $sqlcat = '';
+ if ($in_same_cat) {
+ $sqlcat = " AND post_category = '$current_category' ";
+ }
+
+ $sql_exclude_cats = '';
+ if (!empty($excluded_categories)) {
+ $blah = explode('and', $excluded_categories);
+ foreach($blah as $category) {
+ $category = intval($category);
+ $sql_exclude_cats .= " AND post_category != $category";
+ }
+ }
+
+ $now = current_time('mysql');
+
+ return @$wpdb->get_row("SELECT ID,post_title FROM $wpdb->posts WHERE post_date > '$current_post_date' AND post_date < '$now' AND post_status = 'publish' $sqlcat $sql_exclude_cats AND ID != $post->ID ORDER BY post_date ASC LIMIT 1");
+ }
+
+ function previous_post_link($format='« %link', $link='%title', $in_same_cat = false, $excluded_categories = '') {
+ $post = get_previous_post($in_same_cat, $excluded_categories);
+
+ if(! $post) {
+ return;
+ }
+
+ $title = apply_filters('the_title', $post->post_title);
+
+ $string = '<a href="'.get_permalink($post->ID).'">';
+
+ $link = str_replace('%title', $title, $link);
+
+ $link = $string . $link . '</a>';
+
+ $format = str_replace('%link', $link, $format);
+
+ echo $format;
+ }
+
+ function next_post_link($format='%link »', $link='%title', $in_same_cat = false, $excluded_categories = '') {
+ $post = get_next_post($in_same_cat, $excluded_categories);
+
+ if(! $post) {
+ return;
+ }
+
+ $title = apply_filters('the_title', $post->post_title);
+
+ $string = '<a href="'.get_permalink($post->ID).'">';
+
+ $link = str_replace('%title', $title, $link);
+
+ $link = $string . $link . '</a>';
+
+ $format = str_replace('%link', $link, $format);
+
+ echo $format;
+ }
+
function previous_post($format='%', $previous='previous post: ', $title='yes', $in_same_cat='no', $limitprev=1, $excluded_categories='') {
global $id, $post, $wpdb;
More information about the cvs
mailing list