Make WordPress Core


Ignore:
Timestamp:
10/20/2005 08:48:32 PM (21 years ago)
Author:
ryan
Message:

Image fu from Andy. fixes #1776

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/template-functions-links.php

    r2952 r2958  
    4545    if ( $post->post_status == 'static' )
    4646        return get_page_link($post->ID);
     47    elseif ($post->post_status == 'object')
     48        return get_subpost_link($post->ID);
    4749
    4850    $permalink = get_settings('permalink_structure');
     
    101103}
    102104
     105function get_subpost_link($id = false) {
     106    global $post, $wp_rewrite;
     107
     108    $link = false;
     109
     110    if (! $id) {
     111        $id = $post->ID;
     112    }
     113
     114    $object = get_post($id);
     115    if ( $wp_rewrite->using_permalinks() && ($object->post_parent > 0) ) {
     116        $parent = get_post($object->post_parent);
     117        $parentlink = get_permalink($object->post_parent);
     118        if (! strstr($parentlink, '?') )
     119            $link = trim($parentlink, '/') . '/' . $object->post_name . '/';
     120    }
     121
     122    if (! $link ) {
     123        $link = get_bloginfo('home') . "/?subpost_id=$id";
     124    }
     125
     126    return apply_filters('object_link', $link, $id);
     127}
     128
    103129function get_year_link($year) {
    104130    global $wp_rewrite;
     
    184210    get_currentuserinfo();
    185211
    186     if ( !user_can_edit_post($user_ID, $post->ID) )
     212    if ( !user_can_edit_post($user_ID, $post->ID) || is_subpost() ) {
    187213        return;
     214    }
    188215
    189216    $location = get_settings('siteurl') . "/wp-admin/post.php?action=edit&post=$post->ID";
     
    208235    global $post, $wpdb;
    209236
    210     if ( !is_single() )
     237    if( !is_single() || is_subpost() )
     238        return null;
     239
     240    $current_post_date = $post->post_date;
     241
     242    $join = '';
     243    if ( $in_same_cat ) {
     244        $join = " INNER JOIN $wpdb->post2cat ON $wpdb->posts.ID= $wpdb->post2cat.post_id ";
     245        $cat_array = get_the_category($post->ID);
     246        $join .= ' AND (category_id = ' . intval($cat_array[0]->cat_ID);
     247        for ( $i = 1; $i < (count($cat_array)); $i++ ) {
     248            $join .= ' OR category_id = ' . intval($cat_array[$i]->cat_ID);
     249        }
     250        $join .= ')';
     251    }
     252
     253    $sql_exclude_cats = '';
     254    if ( !empty($excluded_categories) ) {
     255        $blah = explode('and', $excluded_categories);
     256        foreach ( $blah as $category ) {
     257            $category = intval($category);
     258            $sql_exclude_cats .= " AND post_category != $category";
     259        }
     260    }
     261
     262    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");
     263}
     264
     265function get_next_post($in_same_cat = false, $excluded_categories = '') {
     266    global $post, $wpdb;
     267
     268    if( !is_single() || is_subpost() )
    211269        return null;
    212270
     
    233291    }
    234292
    235     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");
    236 }
    237 
    238 function get_next_post($in_same_cat = false, $excluded_categories = '') {
    239     global $post, $wpdb;
    240 
    241     if ( !is_single() )
    242         return null;
    243 
    244     $current_post_date = $post->post_date;
    245    
    246     $join = '';
    247     if ( $in_same_cat ) {
    248         $join = " INNER JOIN $wpdb->post2cat ON $wpdb->posts.ID= $wpdb->post2cat.post_id ";
    249         $cat_array = get_the_category($post->ID);
    250         $join .= ' AND (category_id = ' . intval($cat_array[0]->cat_ID);
    251         for ( $i = 1; $i < (count($cat_array)); $i++ ) {
    252             $join .= ' OR category_id = ' . intval($cat_array[$i]->cat_ID);
    253         }
    254         $join .= ')';
    255     }
    256 
    257     $sql_exclude_cats = '';
    258     if ( !empty($excluded_categories) ) {
    259         $blah = explode('and', $excluded_categories);
    260         foreach ( $blah as $category ) {
    261             $category = intval($category);
    262             $sql_exclude_cats .= " AND post_category != $category";
    263         }
    264     }
    265 
    266293    $now = current_time('mysql');
    267294   
     
    271298
    272299function previous_post_link($format='&laquo; %link', $link='%title', $in_same_cat = false, $excluded_categories = '') {
    273     $post = get_previous_post($in_same_cat, $excluded_categories);
     300    if ( is_subpost() ) {
     301        $post = & get_post($GLOBALS['post']->post_parent);
     302        $pre = __('Belongs to ');
     303    } else {
     304        $post = get_previous_post($in_same_cat, $excluded_categories);
     305        $pre = '';
     306    }
     307
     308    if ( !$post )
     309        return;
     310
     311    $title = apply_filters('the_title', $post->post_title, $post);
     312    $string = '<a href="'.get_permalink($post->ID).'">';
     313    $link = str_replace('%title', $title, $link);
     314    $link = $pre . $string . $link . '</a>';
     315
     316    $format = str_replace('%link', $link, $format);
     317    echo $format;       
     318}
     319
     320function next_post_link($format='%link &raquo;', $link='%title', $in_same_cat = false, $excluded_categories = '') {
     321    $post = get_next_post($in_same_cat, $excluded_categories);
    274322
    275323    if ( !$post )
     
    282330    $format = str_replace('%link', $link, $format);
    283331
    284     echo $format;
    285 }
    286 
    287 function next_post_link($format='%link &raquo;', $link='%title', $in_same_cat = false, $excluded_categories = '') {
    288     $post = get_next_post($in_same_cat, $excluded_categories);
    289 
    290     if ( !$post )
    291         return;
    292 
    293     $title = apply_filters('the_title', $post->post_title, $post);
    294     $string = '<a href="'.get_permalink($post->ID).'">';
    295     $link = str_replace('%title', $title, $link);
    296     $link = $string . $link . '</a>';
    297     $format = str_replace('%link', $link, $format);
    298 
    299     echo $format;
     332    echo $format;       
    300333}
    301334
Note: See TracChangeset for help on using the changeset viewer.