1166 | | * Get adjacent post relational link. |
1167 | | * |
1168 | | * Can either be next or previous post relational link. |
1169 | | * |
1170 | | * @since 2.8.0 |
1171 | | * |
1172 | | * @param string $title Optional. Link title format. |
1173 | | * @param bool $in_same_cat Optional. Whether link should be in same category. |
1174 | | * @param array|string $excluded_categories Optional. Array or comma-separated list of excluded category IDs. |
1175 | | * @param bool $previous Optional, default is true. Whether display link to previous post. |
1176 | | * @return string |
1177 | | */ |
1178 | | function get_adjacent_post_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '', $previous = true) { |
1179 | | if ( $previous && is_attachment() && is_object( $GLOBALS['post'] ) ) |
1180 | | $post = & get_post($GLOBALS['post']->post_parent); |
1181 | | else |
1182 | | $post = get_adjacent_post($in_same_cat,$excluded_categories,$previous); |
1183 | | |
1184 | | if ( empty($post) ) |
1185 | | return; |
1186 | | |
1187 | | if ( empty($post->post_title) ) |
1188 | | $post->post_title = $previous ? __('Previous Post') : __('Next Post'); |
1189 | | |
1190 | | $date = mysql2date(get_option('date_format'), $post->post_date); |
1191 | | |
1192 | | $title = str_replace('%title', $post->post_title, $title); |
1193 | | $title = str_replace('%date', $date, $title); |
1194 | | $title = apply_filters('the_title', $title, $post->ID); |
1195 | | |
1196 | | $link = $previous ? "<link rel='prev' title='" : "<link rel='next' title='"; |
1197 | | $link .= esc_attr( $title ); |
1198 | | $link .= "' href='" . get_permalink($post) . "' />\n"; |
1199 | | |
1200 | | $adjacent = $previous ? 'previous' : 'next'; |
1201 | | return apply_filters( "{$adjacent}_post_rel_link", $link ); |
1202 | | } |
1203 | | |
1204 | | /** |
1205 | | * Display relational links for the posts adjacent to the current post. |
1206 | | * |
1207 | | * @since 2.8.0 |
1208 | | * |
1209 | | * @param string $title Optional. Link title format. |
1210 | | * @param bool $in_same_cat Optional. Whether link should be in same category. |
1211 | | * @param array|string $excluded_categories Optional. Array or comma-separated list of excluded category IDs. |
1212 | | */ |
1213 | | function adjacent_posts_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '') { |
1214 | | echo get_adjacent_post_rel_link($title, $in_same_cat, $excluded_categories = '', true); |
1215 | | echo get_adjacent_post_rel_link($title, $in_same_cat, $excluded_categories = '', false); |
1216 | | } |
1217 | | |
1218 | | /** |
1219 | | * Display relational links for the posts adjacent to the current post for single post pages. |
1220 | | * |
1221 | | * This is meant to be attached to actions like 'wp_head'. Do not call this directly in plugins or theme templates. |
1222 | | * @since 3.0.0 |
1223 | | * |
1224 | | */ |
1225 | | function adjacent_posts_rel_link_wp_head() { |
1226 | | if ( !is_singular() || is_attachment() ) |
1227 | | return; |
1228 | | adjacent_posts_rel_link(); |
1229 | | } |
1230 | | |
1231 | | /** |
1232 | | * Display relational link for the next post adjacent to the current post. |
1233 | | * |
1234 | | * @since 2.8.0 |
1235 | | * |
1236 | | * @param string $title Optional. Link title format. |
1237 | | * @param bool $in_same_cat Optional. Whether link should be in same category. |
1238 | | * @param array|string $excluded_categories Optional. Array or comma-separated list of excluded category IDs. |
1239 | | */ |
1240 | | function next_post_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '') { |
1241 | | echo get_adjacent_post_rel_link($title, $in_same_cat, $excluded_categories = '', false); |
1242 | | } |
1243 | | |
1244 | | /** |
1245 | | * Display relational link for the previous post adjacent to the current post. |
1246 | | * |
1247 | | * @since 2.8.0 |
1248 | | * |
1249 | | * @param string $title Optional. Link title format. |
1250 | | * @param bool $in_same_cat Optional. Whether link should be in same category. |
1251 | | * @param array|string $excluded_categories Optional. Array or comma-separated list of excluded category IDs. |
1252 | | */ |
1253 | | function prev_post_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '') { |
1254 | | echo get_adjacent_post_rel_link($title, $in_same_cat, $excluded_categories = '', true); |
1255 | | } |
1256 | | |
1257 | | /** |
2248 | | * Output rel=canonical for singular queries |
| 2156 | * Get the current archive link |
| 2157 | * |
| 2158 | * @param $paged boolean whether or not to return a link with the current page in the archive, default true |
| 2159 | * @since 3.3 |
| 2160 | */ |
| 2161 | function get_current_archive_link( $paged = true ) { |
| 2162 | if ( is_front_page() ) { |
| 2163 | $link = home_url( '/' ); |
| 2164 | } else if ( is_home() && "page" == get_option('show_on_front') ) { |
| 2165 | $link = get_permalink( get_option( 'page_for_posts' ) ); |
| 2166 | } else if ( is_tax() || is_tag() || is_category() ) { |
| 2167 | $term = get_queried_object(); |
| 2168 | $link = get_term_link( $term, $term->taxonomy ); |
| 2169 | } else if ( is_post_type_archive() ) { |
| 2170 | $link = get_post_type_archive_link( get_post_type() ); |
| 2171 | } else if ( is_author() ) { |
| 2172 | $link = get_author_posts_url( get_query_var('author') ); |
| 2173 | } else if ( is_archive() ) { |
| 2174 | if ( is_date() ) { |
| 2175 | if ( is_day() ) { |
| 2176 | $link = get_day_link( get_query_var('year'), get_query_var('monthnum'), get_query_var('day') ); |
| 2177 | } else if ( is_month() ) { |
| 2178 | $link = get_month_link( get_query_var('year'), get_query_var('monthnum') ); |
| 2179 | } else if ( is_year() ) { |
| 2180 | $link = get_year_link( get_query_var('year') ); |
| 2181 | } |
| 2182 | } |
| 2183 | } |
| 2184 | |
| 2185 | if ( $paged && $link && get_query_var('paged') > 1 ) { |
| 2186 | global $wp_rewrite; |
| 2187 | if ( !$wp_rewrite->using_permalinks() ) { |
| 2188 | $link = add_query_arg( 'paged', get_query_var('paged'), $link ); |
| 2189 | } else { |
| 2190 | $link = user_trailingslashit( trailingslashit( $link ) . trailingslashit( $wp_rewrite->pagination_base ) . get_query_var('paged'), 'archive' ); |
| 2191 | } |
| 2192 | } |
| 2193 | return $link; |
| 2194 | } |
| 2195 | |
| 2196 | /** |
| 2197 | * Output rel=canonical |
2261 | | $link = get_permalink( $id ); |
2262 | | echo "<link rel='canonical' href='$link' />\n"; |
| 2223 | /** |
| 2224 | * Output rel=next and rel=prev links on archives and single pages |
| 2225 | * |
| 2226 | * @since 3.3 |
| 2227 | */ |
| 2228 | function adjacent_rel_links() { |
| 2229 | global $wp_query; |
| 2230 | |
| 2231 | if ( !is_single() ) { |
| 2232 | $url = get_current_archive_link( false ); |
| 2233 | |
| 2234 | if ( $url ) { |
| 2235 | $paged = get_query_var('paged'); |
| 2236 | |
| 2237 | if ( 0 == $paged ) |
| 2238 | $paged = 1; |
| 2239 | |
| 2240 | if ( $paged > 1 ) |
| 2241 | echo get_adjacent_rel_link( "prev", $url, $paged-1, true ); |
| 2242 | |
| 2243 | if ( $paged < $wp_query->max_num_pages ) |
| 2244 | echo get_adjacent_rel_link( "next", $url, $paged+1, true ); |
| 2245 | } |
| 2246 | } else { |
| 2247 | global $page, $numpages, $multipage; |
| 2248 | setup_postdata( $wp_query->post ); |
| 2249 | if ( !$multipage ) |
| 2250 | return; |
| 2251 | |
| 2252 | // Throw current page in another var to not screw up other functionality |
| 2253 | $pg = $page; |
| 2254 | if ( $pg == 0 ) |
| 2255 | $pg = 1; |
| 2256 | |
| 2257 | $url = get_permalink( $post->ID ); |
| 2258 | |
| 2259 | if ( $pg > 1 ) |
| 2260 | echo get_adjacent_rel_link( "prev", $url, $pg-1, false ); |
| 2261 | if ( $pg < $numpages ) |
| 2262 | echo get_adjacent_rel_link( "next", $url, $pg+1, false ); |
| 2263 | } |
| 2267 | * Get adjacent pages link for archives |
| 2268 | * |
| 2269 | * @param string $rel Link relationship, prev or next. |
| 2270 | * @param string $url the unpaginated URL of the current archive. |
| 2271 | * @param string $page the page number to add on to $url for the $link tag. |
| 2272 | * @param boolean $incl_pagination_base whether or not to include /page/ or not. |
| 2273 | * @return string $link link element |
| 2274 | * |
| 2275 | * @since 3.3 |
| 2276 | */ |
| 2277 | function get_adjacent_rel_link( $rel, $url, $page, $incl_pagination_base ) { |
| 2278 | global $wp_rewrite; |
| 2279 | if ( !$wp_rewrite->using_permalinks() ) { |
| 2280 | if ( $page > 1 ) |
| 2281 | $url = add_query_arg( 'paged', $page, $url ); |
| 2282 | } else { |
| 2283 | if ( $page > 1 ) { |
| 2284 | $base = ''; |
| 2285 | if ( $incl_pagination_base ) |
| 2286 | $base = trailingslashit( $wp_rewrite->pagination_base ); |
| 2287 | $url = user_trailingslashit( trailingslashit( $url ) . $base . $page ); |
| 2288 | } |
| 2289 | } |
| 2290 | $link = "<link rel='$rel' href='$url' />\n"; |
| 2291 | return apply_filters( $rel."_rel_link", $link ); |
| 2292 | } |
| 2293 | |
| 2294 | /** |