2004-01-27 10:58:01 +01:00
< ? php
2004-04-21 06:12:55 +02:00
function the_permalink () {
2005-01-15 00:43:20 +01:00
echo apply_filters ( 'the_permalink' , get_permalink ());
2004-04-21 06:12:55 +02:00
}
2004-05-18 10:36:53 +02:00
function permalink_link () { // For backwards compatibility
2005-01-15 00:43:20 +01:00
echo apply_filters ( 'the_permalink' , get_permalink ());
2004-05-18 10:36:53 +02:00
}
2004-01-27 10:58:01 +01:00
function permalink_anchor ( $mode = 'id' ) {
global $id , $post ;
switch ( strtolower ( $mode )) {
case 'title' :
$title = sanitize_title ( $post -> post_title ) . '-' . $id ;
echo '<a id="' . $title . '"></a>' ;
break ;
case 'id' :
default :
echo '<a id="post-' . $id . '"></a>' ;
break ;
}
}
2005-03-27 22:45:01 +02:00
function get_permalink ( $id = 0 ) {
2004-09-05 04:41:01 +02:00
$rewritecode = array (
'%year%' ,
'%monthnum%' ,
'%day%' ,
'%hour%' ,
'%minute%' ,
'%second%' ,
'%postname%' ,
'%post_id%' ,
'%category%' ,
'%author%' ,
'%pagename%'
);
2004-08-10 07:35:59 +02:00
2005-03-27 22:45:01 +02:00
$post = & get_post ( $id );
if ( $post -> post_status == 'static' ) {
return get_page_link ( $post -> ID );
2004-10-06 04:18:37 +02:00
}
2004-11-13 00:08:51 +01:00
2004-09-05 04:41:01 +02:00
$permalink = get_settings ( 'permalink_structure' );
2004-08-10 07:35:59 +02:00
2005-04-09 19:12:36 +02:00
if ( '' != $permalink && 'draft' != $post -> post_status ) {
2005-03-27 22:45:01 +02:00
$unixtime = strtotime ( $post -> post_date );
2004-06-04 04:36:46 +02:00
2005-02-16 16:49:02 +01:00
$category = '' ;
if ( strstr ( $permalink , '%category%' )) {
2005-03-27 22:45:01 +02:00
$cats = get_the_category ( $post -> ID );
2005-02-16 16:49:02 +01:00
$category = $cats [ 0 ] -> category_nicename ;
if ( $parent = $cats [ 0 ] -> category_parent ) $category = get_category_parents ( $parent , FALSE , '/' , TRUE ) . $category ;
}
2005-01-25 06:01:54 +01:00
2005-03-27 22:45:01 +02:00
$authordata = get_userdata ( $post -> post_author );
2004-09-05 04:41:01 +02:00
$author = $authordata -> user_nicename ;
$rewritereplace =
array (
date ( 'Y' , $unixtime ),
date ( 'm' , $unixtime ),
date ( 'd' , $unixtime ),
date ( 'H' , $unixtime ),
date ( 'i' , $unixtime ),
date ( 's' , $unixtime ),
2005-03-27 22:45:01 +02:00
$post -> post_name ,
$post -> ID ,
2004-09-05 04:41:01 +02:00
$category ,
$author ,
2005-03-27 22:45:01 +02:00
$post -> post_name ,
2004-09-05 04:41:01 +02:00
);
2005-03-27 22:45:01 +02:00
return apply_filters ( 'post_link' , get_settings ( 'home' ) . str_replace ( $rewritecode , $rewritereplace , $permalink ), $post );
2004-09-05 04:41:01 +02:00
} else { // if they're not using the fancy permalink option
2005-03-27 22:45:01 +02:00
$permalink = get_settings ( 'home' ) . '/?p=' . $post -> ID ;
return apply_filters ( 'post_link' , $permalink , $post );
2004-09-05 04:41:01 +02:00
}
2004-01-27 10:58:01 +01:00
}
2004-10-06 04:18:37 +02:00
function get_page_link ( $id = false ) {
2004-12-03 03:38:11 +01:00
global $post , $wp_rewrite ;
2004-10-06 04:18:37 +02:00
if ( ! $id ) {
$id = $post -> ID ;
}
2005-01-26 23:46:40 +01:00
$pagestruct = $wp_rewrite -> get_page_permastruct ();
2004-10-06 04:18:37 +02:00
2005-01-26 23:46:40 +01:00
if ( '' != $pagestruct ) {
2004-10-06 04:18:37 +02:00
$link = get_page_uri ( $id );
2005-01-26 23:46:40 +01:00
$link = str_replace ( '%pagename%' , $link , $pagestruct );
2004-10-06 04:18:37 +02:00
$link = get_settings ( 'home' ) . " / $link / " ;
} else {
2005-01-26 23:46:40 +01:00
$link = get_settings ( 'home' ) . " /?page_id= $id " ;
2004-10-06 04:18:37 +02:00
}
2005-02-06 04:40:08 +01:00
return apply_filters ( 'page_link' , $link , $id );
2004-10-06 04:18:37 +02:00
}
2004-11-19 21:54:16 +01:00
function get_year_link ( $year ) {
2005-02-07 08:37:53 +01:00
global $wp_rewrite ;
2004-11-19 21:54:16 +01:00
if ( ! $year ) $year = gmdate ( 'Y' , time () + ( get_settings ( 'gmt_offset' ) * 3600 ));
2004-12-03 03:38:11 +01:00
$yearlink = $wp_rewrite -> get_year_permastruct ();
2004-11-19 21:54:16 +01:00
if ( ! empty ( $yearlink )) {
$yearlink = str_replace ( '%year%' , $year , $yearlink );
2005-02-06 04:40:08 +01:00
return apply_filters ( 'year_link' , get_settings ( 'home' ) . trailingslashit ( $yearlink ), $year );
2004-11-19 21:54:16 +01:00
} else {
2005-02-07 08:37:53 +01:00
return apply_filters ( 'year_link' , get_settings ( 'home' ) . '/?m=' . $year , $year );
2004-11-19 21:54:16 +01:00
}
}
2004-01-27 10:58:01 +01:00
function get_month_link ( $year , $month ) {
2005-02-07 08:37:53 +01:00
global $wp_rewrite ;
2004-04-24 23:52:24 +02:00
if ( ! $year ) $year = gmdate ( 'Y' , time () + ( get_settings ( 'gmt_offset' ) * 3600 ));
if ( ! $month ) $month = gmdate ( 'm' , time () + ( get_settings ( 'gmt_offset' ) * 3600 ));
2004-12-03 03:38:11 +01:00
$monthlink = $wp_rewrite -> get_month_permastruct ();
2004-11-19 21:54:16 +01:00
if ( ! empty ( $monthlink )) {
2004-01-27 10:58:01 +01:00
$monthlink = str_replace ( '%year%' , $year , $monthlink );
$monthlink = str_replace ( '%monthnum%' , zeroise ( intval ( $month ), 2 ), $monthlink );
2005-02-06 04:40:08 +01:00
return apply_filters ( 'month_link' , get_settings ( 'home' ) . trailingslashit ( $monthlink ), $year , $month );
2004-01-27 10:58:01 +01:00
} else {
2005-02-07 08:37:53 +01:00
return apply_filters ( 'month_link' , get_settings ( 'home' ) . '/?m=' . $year . zeroise ( $month , 2 ), $year , $month );
2004-01-27 10:58:01 +01:00
}
}
function get_day_link ( $year , $month , $day ) {
2005-02-07 08:37:53 +01:00
global $wp_rewrite ;
2004-04-24 23:52:24 +02:00
if ( ! $year ) $year = gmdate ( 'Y' , time () + ( get_settings ( 'gmt_offset' ) * 3600 ));
if ( ! $month ) $month = gmdate ( 'm' , time () + ( get_settings ( 'gmt_offset' ) * 3600 ));
if ( ! $day ) $day = gmdate ( 'j' , time () + ( get_settings ( 'gmt_offset' ) * 3600 ));
2004-05-31 19:22:25 +02:00
2004-12-03 03:38:11 +01:00
$daylink = $wp_rewrite -> get_day_permastruct ();
2004-11-19 21:54:16 +01:00
if ( ! empty ( $daylink )) {
2004-01-27 10:58:01 +01:00
$daylink = str_replace ( '%year%' , $year , $daylink );
$daylink = str_replace ( '%monthnum%' , zeroise ( intval ( $month ), 2 ), $daylink );
$daylink = str_replace ( '%day%' , zeroise ( intval ( $day ), 2 ), $daylink );
2005-02-06 04:40:08 +01:00
return apply_filters ( 'day_link' , get_settings ( 'home' ) . trailingslashit ( $daylink ), $year , $month , $day );
2004-01-27 10:58:01 +01:00
} else {
2005-02-07 08:37:53 +01:00
return apply_filters ( 'day_link' , get_settings ( 'home' ) . '/?m=' . $year . zeroise ( $month , 2 ) . zeroise ( $day , 2 ), $year , $month , $day );
2004-01-27 10:58:01 +01:00
}
2004-06-02 09:14:03 +02:00
}
function get_feed_link ( $feed = 'rss2' ) {
2004-12-03 03:38:11 +01:00
global $wp_rewrite ;
2005-01-26 23:46:40 +01:00
$do_perma = 0 ;
$feed_url = get_settings ( 'siteurl' );
$comment_feed_url = $feed_url ;
2004-06-02 09:14:03 +02:00
2005-01-26 23:46:40 +01:00
$permalink = $wp_rewrite -> get_feed_permastruct ();
if ( '' != $permalink ) {
if ( false !== strpos ( $feed , 'comments_' ) ) {
$feed = str_replace ( 'comments_' , '' , $feed );
$permalink = $wp_rewrite -> get_comment_feed_permastruct ();
}
if ( 'rss2' == $feed )
$feed = '' ;
$permalink = str_replace ( '%feed%' , $feed , $permalink );
2005-02-01 03:01:38 +01:00
$permalink = preg_replace ( '#/+#' , '/' , " / $permalink / " );
$output = get_settings ( 'home' ) . $permalink ;
2005-01-26 23:46:40 +01:00
} else {
if ( false !== strpos ( $feed , 'comments_' ) )
2005-02-26 07:12:16 +01:00
$feed = str_replace ( 'comments_' , 'comments-' , $feed );
2005-01-26 23:46:40 +01:00
2005-02-26 07:12:16 +01:00
$output = get_settings ( 'home' ) . " /?feed= { $feed } " ;
2005-01-26 23:46:40 +01:00
}
2004-06-02 09:14:03 +02:00
2005-02-06 04:40:08 +01:00
return apply_filters ( 'feed_link' , $output , $feed );
2004-01-27 10:58:01 +01:00
}
function edit_post_link ( $link = 'Edit This' , $before = '' , $after = '' ) {
2005-02-01 12:14:45 +01:00
global $user_ID , $post ;
2004-01-27 10:58:01 +01:00
get_currentuserinfo ();
2005-02-01 12:14:45 +01:00
if ( ! user_can_edit_post ( $user_ID , $post -> ID )) {
2004-01-27 10:58:01 +01:00
return ;
}
2004-02-26 17:15:48 +01:00
$location = get_settings ( 'siteurl' ) . " /wp-admin/post.php?action=edit&post= $post->ID " ;
2005-09-08 23:40:37 +02:00
echo " $before <a href= \" $location\ " > $link </ a > " . $after ;
2004-01-27 10:58:01 +01:00
}
function edit_comment_link ( $link = 'Edit This' , $before = '' , $after = '' ) {
2005-02-01 12:14:45 +01:00
global $user_ID , $post , $comment ;
2004-01-27 10:58:01 +01:00
get_currentuserinfo ();
2005-02-01 12:14:45 +01:00
if ( ! user_can_edit_post_comments ( $user_ID , $post -> ID )) {
2004-01-27 10:58:01 +01:00
return ;
}
2004-02-26 17:15:48 +01:00
$location = get_settings ( 'siteurl' ) . " /wp-admin/post.php?action=editcomment&comment= $comment->comment_ID " ;
2005-09-08 23:40:37 +02:00
echo " $before <a href=' $location '> $link </a> " . $after ;
2004-01-27 10:58:01 +01:00
}
2004-06-02 09:44:43 +02:00
// Navigation links
2004-08-24 03:35:57 +02:00
function get_previous_post ( $in_same_cat = false , $excluded_categories = '' ) {
2005-04-18 23:47:35 +02:00
global $post , $wpdb ;
2004-08-24 03:35:57 +02:00
2005-04-18 23:47:35 +02:00
if ( ! is_single ()) {
return null ;
}
2004-08-24 03:35:57 +02:00
2005-04-18 23:47:35 +02:00
$current_post_date = $post -> post_date ;
2004-08-24 03:35:57 +02:00
2005-04-18 23:47:35 +02:00
$join = '' ;
if ( $in_same_cat ) {
$join = " INNER JOIN $wpdb->post2cat ON $wpdb->posts .ID= $wpdb->post2cat .post_id " ;
$cat_array = get_the_category ( $post -> ID );
$join .= ' AND (category_id = ' . intval ( $cat_array [ 0 ] -> cat_ID );
for ( $i = 1 ; $i < ( count ( $cat_array )); $i ++ ) {
$join .= ' OR category_id = ' . intval ( $cat_array [ $i ] -> cat_ID );
}
$join .= ')' ;
}
2004-08-24 03:35:57 +02:00
2005-04-18 23:47:35 +02:00
$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 " ;
}
}
2004-08-24 03:35:57 +02:00
2005-04-18 23:47:35 +02:00
return @ $wpdb -> get_row ( " SELECT ID, post_title FROM $wpdb->posts $join WHERE post_date < ' $current_post_date ' AND post_status = 'publish' $sqlcat $sql_exclude_cats ORDER BY post_date DESC LIMIT 1 " );
2004-08-24 03:35:57 +02:00
}
function get_next_post ( $in_same_cat = false , $excluded_categories = '' ) {
2005-04-18 23:47:35 +02:00
global $post , $wpdb ;
2004-08-24 03:35:57 +02:00
2005-04-18 23:47:35 +02:00
if ( ! is_single ()) {
return null ;
}
2004-08-24 03:35:57 +02:00
2005-04-18 23:47:35 +02:00
$current_post_date = $post -> post_date ;
2004-08-24 03:35:57 +02:00
2005-04-18 23:47:35 +02:00
$join = '' ;
if ( $in_same_cat ) {
$join = " INNER JOIN $wpdb->post2cat ON $wpdb->posts .ID= $wpdb->post2cat .post_id " ;
$cat_array = get_the_category ( $post -> ID );
$join .= ' AND (category_id = ' . intval ( $cat_array [ 0 ] -> cat_ID );
for ( $i = 1 ; $i < ( count ( $cat_array )); $i ++ ) {
$join .= ' OR category_id = ' . intval ( $cat_array [ $i ] -> cat_ID );
}
$join .= ')' ;
}
2004-08-24 03:35:57 +02:00
2005-04-18 23:47:35 +02:00
$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 " ;
}
}
2004-08-24 03:35:57 +02:00
2005-04-18 23:47:35 +02:00
$now = current_time ( 'mysql' );
2004-08-24 03:35:57 +02:00
2005-04-18 23:47:35 +02:00
return @ $wpdb -> get_row ( " SELECT ID,post_title FROM $wpdb->posts $join 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 " );
2004-08-24 03:35:57 +02:00
}
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 ;
}
2005-02-06 04:40:08 +01:00
$title = apply_filters ( 'the_title' , $post -> post_title , $post );
2004-08-24 03:35:57 +02:00
$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 ;
}
2005-02-06 04:40:08 +01:00
$title = apply_filters ( 'the_title' , $post -> post_title , $post );
2004-08-24 03:35:57 +02:00
$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 ;
}
2005-04-17 19:09:19 +02:00
// Deprecated. Use previous_post_link().
2004-06-02 09:44:43 +02:00
function previous_post ( $format = '%' , $previous = 'previous post: ' , $title = 'yes' , $in_same_cat = 'no' , $limitprev = 1 , $excluded_categories = '' ) {
2005-04-18 23:47:35 +02:00
if ( empty ( $in_same_cat ) || 'no' == $in_same_cat )
$in_same_cat = false ;
else
$in_same_cat = true ;
$post = get_previous_post ( $in_same_cat , $excluded_categories );
if ( ! $post ) {
return ;
}
$string = '<a href="' . get_permalink ( $post -> ID ) . '">' . $previous ;
if ( $title == 'yes' ) {
$string .= apply_filters ( 'the_title' , $post -> post_title , $post );
}
$string .= '</a>' ;
$format = str_replace ( '%' , $string , $format );
echo $format ;
2004-06-02 09:44:43 +02:00
}
2005-04-17 19:09:19 +02:00
// Deprecated. Use next_post_link().
2004-06-02 09:44:43 +02:00
function next_post ( $format = '%' , $next = 'next post: ' , $title = 'yes' , $in_same_cat = 'no' , $limitnext = 1 , $excluded_categories = '' ) {
2005-04-18 23:47:35 +02:00
if ( empty ( $in_same_cat ) || 'no' == $in_same_cat )
$in_same_cat = false ;
else
$in_same_cat = true ;
$post = get_next_post ( $in_same_cat , $excluded_categories );
if ( ! $post ) {
return ;
}
$string = '<a href="' . get_permalink ( $post -> ID ) . '">' . $next ;
if ( $title == 'yes' ) {
$string .= apply_filters ( 'the_title' , $post -> post_title , $nextpost );
}
$string .= '</a>' ;
$format = str_replace ( '%' , $string , $format );
echo $format ;
2004-06-02 09:44:43 +02:00
}
2005-03-28 04:34:16 +02:00
function get_pagenum_link ( $pagenum = 1 ) {
2004-12-03 03:38:11 +01:00
global $wp_rewrite ;
2005-03-28 04:34:16 +02:00
$qstr = $_SERVER [ 'REQUEST_URI' ];
$page_querystring = " paged " ;
$page_modstring = " page/ " ;
$page_modregex = " page/? " ;
$permalink = 0 ;
$home_root = parse_url ( get_settings ( 'home' ));
$home_root = $home_root [ 'path' ];
$home_root = trailingslashit ( $home_root );
$qstr = preg_replace ( '|^' . $home_root . '|' , '' , $qstr );
$qstr = preg_replace ( '|^/+|' , '' , $qstr );
2005-05-13 23:11:26 +02:00
$index = $_SERVER [ 'PHP_SELF' ];
2005-03-30 08:51:55 +02:00
$index = preg_replace ( '|^' . $home_root . '|' , '' , $index );
$index = preg_replace ( '|^/+|' , '' , $index );
2005-03-28 04:34:16 +02:00
// if we already have a QUERY style page string
if ( stristr ( $qstr , $page_querystring ) ) {
$replacement = " $page_querystring = $pagenum " ;
$qstr = preg_replace ( " / " . $page_querystring . " [^ \ d]+ \ d+/ " , $replacement , $qstr );
// if we already have a mod_rewrite style page string
} elseif ( preg_match ( '|' . $page_modregex . '\d+|' , $qstr ) ){
$permalink = 1 ;
$qstr = preg_replace ( '|' . $page_modregex . '\d+|' , " $page_modstring $pagenum " , $qstr );
// if we don't have a page string at all ...
// lets see what sort of URL we have...
} else {
// we need to know the way queries are being written
// if there's a querystring_start (a "?" usually), it's definitely not mod_rewritten
if ( stristr ( $qstr , '?' ) ){
// so append the query string (using &, since we already have ?)
$qstr .= '&' . $page_querystring . '=' . $pagenum ;
// otherwise, it could be rewritten, OR just the default index ...
} elseif ( '' != get_settings ( 'permalink_structure' ) && ! is_admin ()) {
$permalink = 1 ;
$index = $wp_rewrite -> index ;
// If it's not a path info permalink structure, trim the index.
if ( ! $wp_rewrite -> using_index_permalinks ()) {
$qstr = preg_replace ( " #/* " . $index . " /*# " , '/' , $qstr );
} else {
// If using path info style permalinks, make sure the index is in
// the URI.
if ( strpos ( $qstr , $index ) === false ) {
$qstr = '/' . $index . $qstr ;
}
}
$qstr = trailingslashit ( $qstr ) . $page_modstring . $pagenum ;
} else {
$qstr = $index . '?' . $page_querystring . '=' . $pagenum ;
}
}
2004-06-02 09:44:43 +02:00
2005-03-28 04:34:16 +02:00
$qstr = preg_replace ( '|^/+|' , '' , $qstr );
if ( $permalink ) $qstr = trailingslashit ( $qstr );
2005-08-23 09:43:11 +02:00
$qstr = preg_replace ( '/&([^#])(?![a-z]{1,8};)/' , '&$1' , trailingslashit ( get_settings ( 'home' ) ) . $qstr );
// showing /page/1/ or ?paged=1 is redundant
if ( $pagenum === 1 ) {
$qstr = str_replace ( 'page/1/' , '' , $qstr ); // for mod_rewrite style
$qstr = remove_query_arg ( 'paged' , $qstr ); // for query style
}
return $qstr ;
2004-06-02 09:44:43 +02:00
}
function next_posts ( $max_page = 0 ) { // original by cfactor at cooltux.org
2004-07-29 05:34:08 +02:00
global $paged , $pagenow ;
2004-06-02 09:44:43 +02:00
2004-07-29 05:34:08 +02:00
if ( ! is_single ()) {
2004-06-02 09:44:43 +02:00
if ( ! $paged ) $paged = 1 ;
$nextpage = intval ( $paged ) + 1 ;
if ( ! $max_page || $max_page >= $nextpage ) {
echo get_pagenum_link ( $nextpage );
}
}
}
function next_posts_link ( $label = 'Next Page »' , $max_page = 0 ) {
2005-03-09 05:15:30 +01:00
global $paged , $result , $request , $posts_per_page , $wpdb , $max_num_pages ;
2004-07-29 05:34:08 +02:00
if ( ! $max_page ) {
2005-03-09 05:15:30 +01:00
if ( isset ( $max_num_pages ) ) {
$max_page = $max_num_pages ;
} else {
2005-09-08 23:05:07 +02:00
preg_match ( '#FROM\s(.*)\sGROUP BY#siU' , $request , $matches );
2004-10-13 16:18:17 +02:00
$fromwhere = $matches [ 1 ];
2005-09-08 23:05:07 +02:00
$numposts = $wpdb -> get_var ( " SELECT COUNT(DISTINCT ID) FROM $fromwhere " );
2005-03-09 05:15:30 +01:00
$max_page = $max_num_pages = ceil ( $numposts / $posts_per_page );
}
2004-07-29 05:34:08 +02:00
}
if ( ! $paged )
$paged = 1 ;
$nextpage = intval ( $paged ) + 1 ;
if (( ! is_single ()) && ( empty ( $paged ) || $nextpage <= $max_page )) {
echo '<a href="' ;
next_posts ( $max_page );
echo '">' . preg_replace ( '/&([^#])(?![a-z]{1,8};)/' , '&$1' , $label ) . '</a>' ;
2004-06-02 09:44:43 +02:00
}
}
function previous_posts () { // original by cfactor at cooltux.org
2004-07-29 05:34:08 +02:00
global $_SERVER , $paged , $pagenow ;
2004-06-02 09:44:43 +02:00
2004-07-29 05:34:08 +02:00
if ( ! is_single ()) {
2004-06-02 09:44:43 +02:00
$nextpage = intval ( $paged ) - 1 ;
if ( $nextpage < 1 ) $nextpage = 1 ;
echo get_pagenum_link ( $nextpage );
}
}
function previous_posts_link ( $label = '« Previous Page' ) {
2004-07-29 05:34:08 +02:00
global $paged ;
if (( ! is_single ()) && ( $paged > 1 ) ) {
2004-06-02 09:44:43 +02:00
echo '<a href="' ;
previous_posts ();
echo '">' . preg_replace ( '/&([^#])(?![a-z]{1,8};)/' , '&$1' , $label ) . '</a>' ;
}
}
function posts_nav_link ( $sep = ' — ' , $prelabel = '« Previous Page' , $nxtlabel = 'Next Page »' ) {
2005-03-09 05:15:30 +01:00
global $request , $posts_per_page , $wpdb , $max_num_pages ;
2004-10-12 15:04:35 +02:00
if ( ! is_single ()) {
if ( get_query_var ( 'what_to_show' ) == 'posts' ) {
2005-03-09 05:15:30 +01:00
if ( ! isset ( $max_num_pages ) ) {
2005-09-08 23:05:07 +02:00
preg_match ( '#FROM\s(.*)\sGROUP BY#siU' , $request , $matches );
2005-03-09 05:15:30 +01:00
$fromwhere = $matches [ 1 ];
2005-09-08 23:05:07 +02:00
$numposts = $wpdb -> get_var ( " SELECT COUNT(DISTINCT ID) FROM $fromwhere " );
2005-03-09 05:15:30 +01:00
$max_num_pages = ceil ( $numposts / $posts_per_page );
}
2004-10-12 15:04:35 +02:00
} else {
2005-03-09 05:15:30 +01:00
$max_num_pages = 999999 ;
2004-10-12 15:04:35 +02:00
}
2004-08-17 00:50:06 +02:00
2005-03-09 05:15:30 +01:00
if ( $max_num_pages > 1 ) {
2004-06-02 09:44:43 +02:00
previous_posts_link ( $prelabel );
echo preg_replace ( '/&([^#])(?![a-z]{1,8};)/' , '&$1' , $sep );
next_posts_link ( $nxtlabel , $max_page );
}
}
}
2005-09-08 23:40:37 +02:00
?>