WordPress.org

Make WordPress Core

Ticket #8703: 8703.diff

File 8703.diff, 3.2 KB (added by sivel, 9 years ago)
  • link-template.php

     
    970970}
    971971
    972972/**
     973 * Display adjacent post relational link.
     974 *
     975 * Can either be next or previous post relational link.
     976 *
     977 * @since 2.8.0
     978 *
     979 * @param string $title Optional. Link title format.
     980 * @param bool $in_same_cat Optional. Whether link should be in same category.
     981 * @param string $excluded_categories Optional. Excluded categories IDs.
     982 * @param bool $previous Optional, default is true. Whether display link to previous post.
     983 */
     984//function get_adjacent_post_rel_link($prev = true, $next = true) {
     985function adjacent_post_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '', $previous = true) {
     986        if ( $previous && is_attachment() )
     987                $post = & get_post($GLOBALS['post']->post_parent);
     988        else
     989                $post = get_adjacent_post($in_same_cat,$excluded_categories,$previous);
     990
     991        if ( !$post )
     992                return;
     993
     994        if ( empty($post->post_title) )
     995                $post->post_title = $previous ? __('Previous Post') : __('Next Post');
     996
     997        $date = mysql2date(get_option('date_format'), $post->post_date);
     998
     999        $title = str_replace('%title', $post->post_title, $title);
     1000        $title = str_replace('%date', $date, $title);
     1001
     1002        $title = apply_filters('the_title', $title, $post);
     1003       
     1004        $link .= $previous ? "<link rel='prev' title='" : "<link rel='next' title='";
     1005        $link .= $title;
     1006        $link .= "' href='" . get_permalink($post) . "' />\n";
     1007
     1008        $adjacent = $previous ? 'previous' : 'next';
     1009        echo apply_filters( "{$adjacent}_post_rel_link", $link );
     1010}
     1011
     1012/**
     1013 * Display relational links for the posts adjacent to the current post.
     1014 *
     1015 * @since 2.8.0
     1016 *
     1017 * @param string $title Optional. Link title format.
     1018 * @param bool $in_same_cat Optional. Whether link should be in same category.
     1019 * @param string $excluded_categories Optional. Excluded categories IDs.
     1020 */
     1021function adjacent_posts_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '') {
     1022        adjacent_post_rel_link($title, $in_same_cat, $excluded_categories = '', true);
     1023        adjacent_post_rel_link($title, $in_same_cat, $excluded_categories = '', false);
     1024}
     1025
     1026/**
     1027 * Display relational link for the next post adjacent to the current post.
     1028 *
     1029 * @since 2.8.0
     1030 *
     1031 * @param string $title Optional. Link title format.
     1032 * @param bool $in_same_cat Optional. Whether link should be in same category.
     1033 * @param string $excluded_categories Optional. Excluded categories IDs.
     1034 */
     1035function next_post_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '') {
     1036        adjacent_post_rel_link($title, $in_same_cat, $excluded_categories = '', false);
     1037}
     1038
     1039/**
     1040 * Display relational link for the previous post adjacent to the current post.
     1041 *
     1042 * @since 2.8.0
     1043 *
     1044 * @param string $title Optional. Link title format.
     1045 * @param bool $in_same_cat Optional. Whether link should be in same category.
     1046 * @param string $excluded_categories Optional. Excluded categories IDs.
     1047 */
     1048function prev_post_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '') {
     1049        adjacent_post_rel_link($title, $in_same_cat, $excluded_categories = '', true);
     1050}
     1051
     1052/**
    9731053 * Retrieve get links for page numbers.
    9741054 *
    9751055 * @since 1.5.0