raw
mp-wp_genesis           1 <?php
mp-wp_genesis 2 /**
mp-wp_genesis 3 * WordPress Link Template Functions
mp-wp_genesis 4 *
mp-wp_genesis 5 * @package WordPress
mp-wp_genesis 6 * @subpackage Template
mp-wp_genesis 7 */
mp-wp_genesis 8
mp-wp_genesis 9 /**
mp-wp_genesis 10 * Display the permalink for the current post.
mp-wp_genesis 11 *
mp-wp_genesis 12 * @since 1.2.0
mp-wp_genesis 13 * @uses apply_filters() Calls 'the_permalink' filter on the permalink string.
mp-wp_genesis 14 */
mp-wp_genesis 15 function the_permalink() {
mp-wp_genesis 16 echo apply_filters('the_permalink', get_permalink());
mp-wp_genesis 17 }
mp-wp_genesis 18
mp-wp_genesis 19 /**
mp-wp_genesis 20 * Retrieve trailing slash string, if blog set for adding trailing slashes.
mp-wp_genesis 21 *
mp-wp_genesis 22 * Conditionally adds a trailing slash if the permalink structure has a trailing
mp-wp_genesis 23 * slash, strips the trailing slash if not. The string is passed through the
mp-wp_genesis 24 * 'user_trailingslashit' filter. Will remove trailing slash from string, if
mp-wp_genesis 25 * blog is not set to have them.
mp-wp_genesis 26 *
mp-wp_genesis 27 * @since 2.2.0
mp-wp_genesis 28 * @uses $wp_rewrite
mp-wp_genesis 29 *
mp-wp_genesis 30 * @param $string String a URL with or without a trailing slash.
mp-wp_genesis 31 * @param $type_of_url String the type of URL being considered (e.g. single, category, etc) for use in the filter.
mp-wp_genesis 32 * @return string
mp-wp_genesis 33 */
mp-wp_genesis 34 function user_trailingslashit($string, $type_of_url = '') {
mp-wp_genesis 35 global $wp_rewrite;
mp-wp_genesis 36 if ( $wp_rewrite->use_trailing_slashes )
mp-wp_genesis 37 $string = trailingslashit($string);
mp-wp_genesis 38 else
mp-wp_genesis 39 $string = untrailingslashit($string);
mp-wp_genesis 40
mp-wp_genesis 41 // Note that $type_of_url can be one of following:
mp-wp_genesis 42 // single, single_trackback, single_feed, single_paged, feed, category, page, year, month, day, paged
mp-wp_genesis 43 $string = apply_filters('user_trailingslashit', $string, $type_of_url);
mp-wp_genesis 44 return $string;
mp-wp_genesis 45 }
mp-wp_genesis 46
mp-wp_genesis 47 /**
mp-wp_genesis 48 * Display permalink anchor for current post.
mp-wp_genesis 49 *
mp-wp_genesis 50 * The permalink mode title will use the post title for the 'a' element 'id'
mp-wp_genesis 51 * attribute. The id mode uses 'post-' with the post ID for the 'id' attribute.
mp-wp_genesis 52 *
mp-wp_genesis 53 * @since 0.71
mp-wp_genesis 54 *
mp-wp_genesis 55 * @param string $mode Permalink mode can be either 'title', 'id', or default, which is 'id'.
mp-wp_genesis 56 */
mp-wp_genesis 57 function permalink_anchor($mode = 'id') {
mp-wp_genesis 58 global $post;
mp-wp_genesis 59 switch ( strtolower($mode) ) {
mp-wp_genesis 60 case 'title':
mp-wp_genesis 61 $title = sanitize_title($post->post_title) . '-' . $post->ID;
mp-wp_genesis 62 echo '<a id="'.$title.'"></a>';
mp-wp_genesis 63 break;
mp-wp_genesis 64 case 'id':
mp-wp_genesis 65 default:
mp-wp_genesis 66 echo '<a id="post-' . $post->ID . '"></a>';
mp-wp_genesis 67 break;
mp-wp_genesis 68 }
mp-wp_genesis 69 }
mp-wp_genesis 70
mp-wp_genesis 71 /**
mp-wp_genesis 72 * Retrieve full permalink for current post or post ID.
mp-wp_genesis 73 *
mp-wp_genesis 74 * @since 1.0.0
mp-wp_genesis 75 *
mp-wp_genesis 76 * @param int $id Optional. Post ID.
mp-wp_genesis 77 * @param bool $leavename Optional, defaults to false. Whether to keep post name or page name.
mp-wp_genesis 78 * @return string
mp-wp_genesis 79 */
mp-wp_genesis 80 function get_permalink($id = 0, $leavename = false) {
mp-wp_genesis 81 $rewritecode = array(
mp-wp_genesis 82 '%year%',
mp-wp_genesis 83 '%monthnum%',
mp-wp_genesis 84 '%day%',
mp-wp_genesis 85 '%hour%',
mp-wp_genesis 86 '%minute%',
mp-wp_genesis 87 '%second%',
mp-wp_genesis 88 $leavename? '' : '%postname%',
mp-wp_genesis 89 '%post_id%',
mp-wp_genesis 90 '%category%',
mp-wp_genesis 91 '%author%',
mp-wp_genesis 92 $leavename? '' : '%pagename%',
mp-wp_genesis 93 );
mp-wp_genesis 94
mp-wp_genesis 95 $post = &get_post($id);
mp-wp_genesis 96
mp-wp_genesis 97 if ( empty($post->ID) ) return false;
mp-wp_genesis 98
mp-wp_genesis 99 if ( $post->post_type == 'page' )
mp-wp_genesis 100 return get_page_link($post->ID, $leavename);
mp-wp_genesis 101 elseif ($post->post_type == 'attachment')
mp-wp_genesis 102 return get_attachment_link($post->ID);
mp-wp_genesis 103
mp-wp_genesis 104 $permalink = get_option('permalink_structure');
mp-wp_genesis 105
mp-wp_genesis 106 if ( '' != $permalink && !in_array($post->post_status, array('draft', 'pending')) ) {
mp-wp_genesis 107 $unixtime = strtotime($post->post_date);
mp-wp_genesis 108
mp-wp_genesis 109 $category = '';
mp-wp_genesis 110 if ( strpos($permalink, '%category%') !== false ) {
mp-wp_genesis 111 $cats = get_the_category($post->ID);
mp-wp_genesis 112 if ( $cats ) {
mp-wp_genesis 113 usort($cats, '_usort_terms_by_ID'); // order by ID
mp-wp_genesis 114 $category = $cats[0]->slug;
mp-wp_genesis 115 if ( $parent = $cats[0]->parent )
mp-wp_genesis 116 $category = get_category_parents($parent, false, '/', true) . $category;
mp-wp_genesis 117 }
mp-wp_genesis 118 // show default category in permalinks, without
mp-wp_genesis 119 // having to assign it explicitly
mp-wp_genesis 120 if ( empty($category) ) {
mp-wp_genesis 121 $default_category = get_category( get_option( 'default_category' ) );
mp-wp_genesis 122 $category = is_wp_error( $default_category ) ? '' : $default_category->slug;
mp-wp_genesis 123 }
mp-wp_genesis 124 }
mp-wp_genesis 125
mp-wp_genesis 126 $author = '';
mp-wp_genesis 127 if ( strpos($permalink, '%author%') !== false ) {
mp-wp_genesis 128 $authordata = get_userdata($post->post_author);
mp-wp_genesis 129 $author = $authordata->user_nicename;
mp-wp_genesis 130 }
mp-wp_genesis 131
mp-wp_genesis 132 $date = explode(" ",date('Y m d H i s', $unixtime));
mp-wp_genesis 133 $rewritereplace =
mp-wp_genesis 134 array(
mp-wp_genesis 135 $date[0],
mp-wp_genesis 136 $date[1],
mp-wp_genesis 137 $date[2],
mp-wp_genesis 138 $date[3],
mp-wp_genesis 139 $date[4],
mp-wp_genesis 140 $date[5],
mp-wp_genesis 141 $post->post_name,
mp-wp_genesis 142 $post->ID,
mp-wp_genesis 143 $category,
mp-wp_genesis 144 $author,
mp-wp_genesis 145 $post->post_name,
mp-wp_genesis 146 );
mp-wp_genesis 147 $permalink = get_option('home') . str_replace($rewritecode, $rewritereplace, $permalink);
mp-wp_genesis 148 $permalink = user_trailingslashit($permalink, 'single');
mp-wp_genesis 149 return apply_filters('post_link', $permalink, $post, $leavename);
mp-wp_genesis 150 } else { // if they're not using the fancy permalink option
mp-wp_genesis 151 $permalink = get_option('home') . '/?p=' . $post->ID;
mp-wp_genesis 152 return apply_filters('post_link', $permalink, $post, $leavename);
mp-wp_genesis 153 }
mp-wp_genesis 154 }
mp-wp_genesis 155
mp-wp_genesis 156 /**
mp-wp_genesis 157 * Retrieve permalink from post ID.
mp-wp_genesis 158 *
mp-wp_genesis 159 * @since 1.0.0
mp-wp_genesis 160 *
mp-wp_genesis 161 * @param int $post_id Optional. Post ID.
mp-wp_genesis 162 * @param mixed $deprecated Not used.
mp-wp_genesis 163 * @return string
mp-wp_genesis 164 */
mp-wp_genesis 165 function post_permalink($post_id = 0, $deprecated = '') {
mp-wp_genesis 166 return get_permalink($post_id);
mp-wp_genesis 167 }
mp-wp_genesis 168
mp-wp_genesis 169 /**
mp-wp_genesis 170 * Retrieve the permalink for current page or page ID.
mp-wp_genesis 171 *
mp-wp_genesis 172 * Respects page_on_front. Use this one.
mp-wp_genesis 173 *
mp-wp_genesis 174 * @since 1.5.0
mp-wp_genesis 175 *
mp-wp_genesis 176 * @param int $id Optional. Post ID.
mp-wp_genesis 177 * @param bool $leavename Optional, defaults to false. Whether to keep post name or page name.
mp-wp_genesis 178 * @return string
mp-wp_genesis 179 */
mp-wp_genesis 180 function get_page_link($id = false, $leavename = false) {
mp-wp_genesis 181 global $post;
mp-wp_genesis 182
mp-wp_genesis 183 $id = (int) $id;
mp-wp_genesis 184 if ( !$id )
mp-wp_genesis 185 $id = (int) $post->ID;
mp-wp_genesis 186
mp-wp_genesis 187 if ( 'page' == get_option('show_on_front') && $id == get_option('page_on_front') )
mp-wp_genesis 188 $link = get_option('home');
mp-wp_genesis 189 else
mp-wp_genesis 190 $link = _get_page_link( $id , $leavename );
mp-wp_genesis 191
mp-wp_genesis 192 return apply_filters('page_link', $link, $id);
mp-wp_genesis 193 }
mp-wp_genesis 194
mp-wp_genesis 195 /**
mp-wp_genesis 196 * Retrieve the page permalink.
mp-wp_genesis 197 *
mp-wp_genesis 198 * Ignores page_on_front. Internal use only.
mp-wp_genesis 199 *
mp-wp_genesis 200 * @since 2.1.0
mp-wp_genesis 201 * @access private
mp-wp_genesis 202 *
mp-wp_genesis 203 * @param int $id Optional. Post ID.
mp-wp_genesis 204 * @param bool $leavename Optional. Leave name.
mp-wp_genesis 205 * @return string
mp-wp_genesis 206 */
mp-wp_genesis 207 function _get_page_link( $id = false, $leavename = false ) {
mp-wp_genesis 208 global $post, $wp_rewrite;
mp-wp_genesis 209
mp-wp_genesis 210 if ( !$id )
mp-wp_genesis 211 $id = (int) $post->ID;
mp-wp_genesis 212 else
mp-wp_genesis 213 $post = &get_post($id);
mp-wp_genesis 214
mp-wp_genesis 215 $pagestruct = $wp_rewrite->get_page_permastruct();
mp-wp_genesis 216
mp-wp_genesis 217 if ( '' != $pagestruct && isset($post->post_status) && 'draft' != $post->post_status ) {
mp-wp_genesis 218 $link = get_page_uri($id);
mp-wp_genesis 219 $link = ( $leavename ) ? $pagestruct : str_replace('%pagename%', $link, $pagestruct);
mp-wp_genesis 220 $link = get_option('home') . "/$link";
mp-wp_genesis 221 $link = user_trailingslashit($link, 'page');
mp-wp_genesis 222 } else {
mp-wp_genesis 223 $link = get_option('home') . "/?page_id=$id";
mp-wp_genesis 224 }
mp-wp_genesis 225
mp-wp_genesis 226 return apply_filters( '_get_page_link', $link, $id );
mp-wp_genesis 227 }
mp-wp_genesis 228
mp-wp_genesis 229 /**
mp-wp_genesis 230 * Retrieve permalink for attachment.
mp-wp_genesis 231 *
mp-wp_genesis 232 * This can be used in the WordPress Loop or outside of it.
mp-wp_genesis 233 *
mp-wp_genesis 234 * @since 2.0.0
mp-wp_genesis 235 *
mp-wp_genesis 236 * @param int $id Optional. Post ID.
mp-wp_genesis 237 * @return string
mp-wp_genesis 238 */
mp-wp_genesis 239 function get_attachment_link($id = false) {
mp-wp_genesis 240 global $post, $wp_rewrite;
mp-wp_genesis 241
mp-wp_genesis 242 $link = false;
mp-wp_genesis 243
mp-wp_genesis 244 if (! $id) {
mp-wp_genesis 245 $id = (int) $post->ID;
mp-wp_genesis 246 }
mp-wp_genesis 247
mp-wp_genesis 248 $object = get_post($id);
mp-wp_genesis 249 if ( $wp_rewrite->using_permalinks() && ($object->post_parent > 0) && ($object->post_parent != $id) ) {
mp-wp_genesis 250 $parent = get_post($object->post_parent);
mp-wp_genesis 251 if ( 'page' == $parent->post_type )
mp-wp_genesis 252 $parentlink = _get_page_link( $object->post_parent ); // Ignores page_on_front
mp-wp_genesis 253 else
mp-wp_genesis 254 $parentlink = get_permalink( $object->post_parent );
mp-wp_genesis 255 if ( is_numeric($object->post_name) || false !== strpos(get_option('permalink_structure'), '%category%') )
mp-wp_genesis 256 $name = 'attachment/' . $object->post_name; // <permalink>/<int>/ is paged so we use the explicit attachment marker
mp-wp_genesis 257 else
mp-wp_genesis 258 $name = $object->post_name;
mp-wp_genesis 259 if (strpos($parentlink, '?') === false)
mp-wp_genesis 260 $link = user_trailingslashit( trailingslashit($parentlink) . $name );
mp-wp_genesis 261 }
mp-wp_genesis 262
mp-wp_genesis 263 if (! $link ) {
mp-wp_genesis 264 $link = get_bloginfo('url') . "/?attachment_id=$id";
mp-wp_genesis 265 }
mp-wp_genesis 266
mp-wp_genesis 267 return apply_filters('attachment_link', $link, $id);
mp-wp_genesis 268 }
mp-wp_genesis 269
mp-wp_genesis 270 /**
mp-wp_genesis 271 * Retrieve the permalink for the year archives.
mp-wp_genesis 272 *
mp-wp_genesis 273 * @since 1.5.0
mp-wp_genesis 274 *
mp-wp_genesis 275 * @param int|bool $year False for current year or year for permalink.
mp-wp_genesis 276 * @return string
mp-wp_genesis 277 */
mp-wp_genesis 278 function get_year_link($year) {
mp-wp_genesis 279 global $wp_rewrite;
mp-wp_genesis 280 if ( !$year )
mp-wp_genesis 281 $year = gmdate('Y', time()+(get_option('gmt_offset') * 3600));
mp-wp_genesis 282 $yearlink = $wp_rewrite->get_year_permastruct();
mp-wp_genesis 283 if ( !empty($yearlink) ) {
mp-wp_genesis 284 $yearlink = str_replace('%year%', $year, $yearlink);
mp-wp_genesis 285 return apply_filters('year_link', get_option('home') . user_trailingslashit($yearlink, 'year'), $year);
mp-wp_genesis 286 } else {
mp-wp_genesis 287 return apply_filters('year_link', get_option('home') . '/?m=' . $year, $year);
mp-wp_genesis 288 }
mp-wp_genesis 289 }
mp-wp_genesis 290
mp-wp_genesis 291 /**
mp-wp_genesis 292 * Retrieve the permalink for the month archives with year.
mp-wp_genesis 293 *
mp-wp_genesis 294 * @since 1.0.0
mp-wp_genesis 295 *
mp-wp_genesis 296 * @param bool|int $year False for current year. Integer of year.
mp-wp_genesis 297 * @param bool|int $month False for current month. Integer of month.
mp-wp_genesis 298 * @return string
mp-wp_genesis 299 */
mp-wp_genesis 300 function get_month_link($year, $month) {
mp-wp_genesis 301 global $wp_rewrite;
mp-wp_genesis 302 if ( !$year )
mp-wp_genesis 303 $year = gmdate('Y', time()+(get_option('gmt_offset') * 3600));
mp-wp_genesis 304 if ( !$month )
mp-wp_genesis 305 $month = gmdate('m', time()+(get_option('gmt_offset') * 3600));
mp-wp_genesis 306 $monthlink = $wp_rewrite->get_month_permastruct();
mp-wp_genesis 307 if ( !empty($monthlink) ) {
mp-wp_genesis 308 $monthlink = str_replace('%year%', $year, $monthlink);
mp-wp_genesis 309 $monthlink = str_replace('%monthnum%', zeroise(intval($month), 2), $monthlink);
mp-wp_genesis 310 return apply_filters('month_link', get_option('home') . user_trailingslashit($monthlink, 'month'), $year, $month);
mp-wp_genesis 311 } else {
mp-wp_genesis 312 return apply_filters('month_link', get_option('home') . '/?m=' . $year . zeroise($month, 2), $year, $month);
mp-wp_genesis 313 }
mp-wp_genesis 314 }
mp-wp_genesis 315
mp-wp_genesis 316 /**
mp-wp_genesis 317 * Retrieve the permalink for the day archives with year and month.
mp-wp_genesis 318 *
mp-wp_genesis 319 * @since 1.0.0
mp-wp_genesis 320 *
mp-wp_genesis 321 * @param bool|int $year False for current year. Integer of year.
mp-wp_genesis 322 * @param bool|int $month False for current month. Integer of month.
mp-wp_genesis 323 * @param bool|int $day False for current day. Integer of day.
mp-wp_genesis 324 * @return string
mp-wp_genesis 325 */
mp-wp_genesis 326 function get_day_link($year, $month, $day) {
mp-wp_genesis 327 global $wp_rewrite;
mp-wp_genesis 328 if ( !$year )
mp-wp_genesis 329 $year = gmdate('Y', time()+(get_option('gmt_offset') * 3600));
mp-wp_genesis 330 if ( !$month )
mp-wp_genesis 331 $month = gmdate('m', time()+(get_option('gmt_offset') * 3600));
mp-wp_genesis 332 if ( !$day )
mp-wp_genesis 333 $day = gmdate('j', time()+(get_option('gmt_offset') * 3600));
mp-wp_genesis 334
mp-wp_genesis 335 $daylink = $wp_rewrite->get_day_permastruct();
mp-wp_genesis 336 if ( !empty($daylink) ) {
mp-wp_genesis 337 $daylink = str_replace('%year%', $year, $daylink);
mp-wp_genesis 338 $daylink = str_replace('%monthnum%', zeroise(intval($month), 2), $daylink);
mp-wp_genesis 339 $daylink = str_replace('%day%', zeroise(intval($day), 2), $daylink);
mp-wp_genesis 340 return apply_filters('day_link', get_option('home') . user_trailingslashit($daylink, 'day'), $year, $month, $day);
mp-wp_genesis 341 } else {
mp-wp_genesis 342 return apply_filters('day_link', get_option('home') . '/?m=' . $year . zeroise($month, 2) . zeroise($day, 2), $year, $month, $day);
mp-wp_genesis 343 }
mp-wp_genesis 344 }
mp-wp_genesis 345
mp-wp_genesis 346 /**
mp-wp_genesis 347 * Retrieve the permalink for the feed type.
mp-wp_genesis 348 *
mp-wp_genesis 349 * @since 1.5.0
mp-wp_genesis 350 *
mp-wp_genesis 351 * @param string $feed Optional, defaults to default feed. Feed type.
mp-wp_genesis 352 * @return string
mp-wp_genesis 353 */
mp-wp_genesis 354 function get_feed_link($feed = '') {
mp-wp_genesis 355 global $wp_rewrite;
mp-wp_genesis 356
mp-wp_genesis 357 $permalink = $wp_rewrite->get_feed_permastruct();
mp-wp_genesis 358 if ( '' != $permalink ) {
mp-wp_genesis 359 if ( false !== strpos($feed, 'comments_') ) {
mp-wp_genesis 360 $feed = str_replace('comments_', '', $feed);
mp-wp_genesis 361 $permalink = $wp_rewrite->get_comment_feed_permastruct();
mp-wp_genesis 362 }
mp-wp_genesis 363
mp-wp_genesis 364 if ( get_default_feed() == $feed )
mp-wp_genesis 365 $feed = '';
mp-wp_genesis 366
mp-wp_genesis 367 $permalink = str_replace('%feed%', $feed, $permalink);
mp-wp_genesis 368 $permalink = preg_replace('#/+#', '/', "/$permalink");
mp-wp_genesis 369 $output = get_option('home') . user_trailingslashit($permalink, 'feed');
mp-wp_genesis 370 } else {
mp-wp_genesis 371 if ( empty($feed) )
mp-wp_genesis 372 $feed = get_default_feed();
mp-wp_genesis 373
mp-wp_genesis 374 if ( false !== strpos($feed, 'comments_') )
mp-wp_genesis 375 $feed = str_replace('comments_', 'comments-', $feed);
mp-wp_genesis 376
mp-wp_genesis 377 $output = get_option('home') . "/?feed={$feed}";
mp-wp_genesis 378 }
mp-wp_genesis 379
mp-wp_genesis 380 return apply_filters('feed_link', $output, $feed);
mp-wp_genesis 381 }
mp-wp_genesis 382
mp-wp_genesis 383 /**
mp-wp_genesis 384 * Retrieve the permalink for the post comments feed.
mp-wp_genesis 385 *
mp-wp_genesis 386 * @since 2.2.0
mp-wp_genesis 387 *
mp-wp_genesis 388 * @param int $post_id Optional. Post ID.
mp-wp_genesis 389 * @param string $feed Optional. Feed type.
mp-wp_genesis 390 * @return string
mp-wp_genesis 391 */
mp-wp_genesis 392 function get_post_comments_feed_link($post_id = '', $feed = '') {
mp-wp_genesis 393 global $id;
mp-wp_genesis 394
mp-wp_genesis 395 if ( empty($post_id) )
mp-wp_genesis 396 $post_id = (int) $id;
mp-wp_genesis 397
mp-wp_genesis 398 if ( empty($feed) )
mp-wp_genesis 399 $feed = get_default_feed();
mp-wp_genesis 400
mp-wp_genesis 401 if ( '' != get_option('permalink_structure') ) {
mp-wp_genesis 402 $url = trailingslashit( get_permalink($post_id) ) . 'feed';
mp-wp_genesis 403 if ( $feed != get_default_feed() )
mp-wp_genesis 404 $url .= "/$feed";
mp-wp_genesis 405 $url = user_trailingslashit($url, 'single_feed');
mp-wp_genesis 406 } else {
mp-wp_genesis 407 $type = get_post_field('post_type', $post_id);
mp-wp_genesis 408 if ( 'page' == $type )
mp-wp_genesis 409 $url = get_option('home') . "/?feed=$feed&amp;page_id=$post_id";
mp-wp_genesis 410 else
mp-wp_genesis 411 $url = get_option('home') . "/?feed=$feed&amp;p=$post_id";
mp-wp_genesis 412 }
mp-wp_genesis 413
mp-wp_genesis 414 return apply_filters('post_comments_feed_link', $url);
mp-wp_genesis 415 }
mp-wp_genesis 416
mp-wp_genesis 417 /**
mp-wp_genesis 418 * Display the comment feed link for a post.
mp-wp_genesis 419 *
mp-wp_genesis 420 * Prints out the comment feed link for a post. Link text is placed in the
mp-wp_genesis 421 * anchor. If no link text is specified, default text is used. If no post ID is
mp-wp_genesis 422 * specified, the current post is used.
mp-wp_genesis 423 *
mp-wp_genesis 424 * @package WordPress
mp-wp_genesis 425 * @subpackage Feed
mp-wp_genesis 426 * @since 2.5.0
mp-wp_genesis 427 *
mp-wp_genesis 428 * @param string $link_text Descriptive text.
mp-wp_genesis 429 * @param int $post_id Optional post ID. Default to current post.
mp-wp_genesis 430 * @param string $feed Optional. Feed format.
mp-wp_genesis 431 * @return string Link to the comment feed for the current post.
mp-wp_genesis 432 */
mp-wp_genesis 433 function post_comments_feed_link( $link_text = '', $post_id = '', $feed = '' ) {
mp-wp_genesis 434 $url = get_post_comments_feed_link($post_id, $feed);
mp-wp_genesis 435 if ( empty($link_text) )
mp-wp_genesis 436 $link_text = __('Comments Feed');
mp-wp_genesis 437
mp-wp_genesis 438 echo "<a href='$url'>$link_text</a>";
mp-wp_genesis 439 }
mp-wp_genesis 440
mp-wp_genesis 441 /**
mp-wp_genesis 442 * Retrieve the feed link for a given author.
mp-wp_genesis 443 *
mp-wp_genesis 444 * Returns a link to the feed for all posts by a given author. A specific feed
mp-wp_genesis 445 * can be requested or left blank to get the default feed.
mp-wp_genesis 446 *
mp-wp_genesis 447 * @package WordPress
mp-wp_genesis 448 * @subpackage Feed
mp-wp_genesis 449 * @since 2.5.0
mp-wp_genesis 450 *
mp-wp_genesis 451 * @param int $author_id ID of an author.
mp-wp_genesis 452 * @param string $feed Optional. Feed type.
mp-wp_genesis 453 * @return string Link to the feed for the author specified by $author_id.
mp-wp_genesis 454 */
mp-wp_genesis 455 function get_author_feed_link( $author_id, $feed = '' ) {
mp-wp_genesis 456 $author_id = (int) $author_id;
mp-wp_genesis 457 $permalink_structure = get_option('permalink_structure');
mp-wp_genesis 458
mp-wp_genesis 459 if ( empty($feed) )
mp-wp_genesis 460 $feed = get_default_feed();
mp-wp_genesis 461
mp-wp_genesis 462 if ( '' == $permalink_structure ) {
mp-wp_genesis 463 $link = get_option('home') . "?feed=$feed&amp;author=" . $author_id;
mp-wp_genesis 464 } else {
mp-wp_genesis 465 $link = get_author_posts_url($author_id);
mp-wp_genesis 466 if ( $feed == get_default_feed() )
mp-wp_genesis 467 $feed_link = 'feed';
mp-wp_genesis 468 else
mp-wp_genesis 469 $feed_link = "feed/$feed";
mp-wp_genesis 470
mp-wp_genesis 471 $link = trailingslashit($link) . user_trailingslashit($feed_link, 'feed');
mp-wp_genesis 472 }
mp-wp_genesis 473
mp-wp_genesis 474 $link = apply_filters('author_feed_link', $link, $feed);
mp-wp_genesis 475
mp-wp_genesis 476 return $link;
mp-wp_genesis 477 }
mp-wp_genesis 478
mp-wp_genesis 479 /**
mp-wp_genesis 480 * Retrieve the feed link for a category.
mp-wp_genesis 481 *
mp-wp_genesis 482 * Returns a link to the feed for all post in a given category. A specific feed
mp-wp_genesis 483 * can be requested or left blank to get the default feed.
mp-wp_genesis 484 *
mp-wp_genesis 485 * @package WordPress
mp-wp_genesis 486 * @subpackage Feed
mp-wp_genesis 487 * @since 2.5.0
mp-wp_genesis 488 *
mp-wp_genesis 489 * @param int $cat_id ID of a category.
mp-wp_genesis 490 * @param string $feed Optional. Feed type.
mp-wp_genesis 491 * @return string Link to the feed for the category specified by $cat_id.
mp-wp_genesis 492 */
mp-wp_genesis 493 function get_category_feed_link($cat_id, $feed = '') {
mp-wp_genesis 494 $cat_id = (int) $cat_id;
mp-wp_genesis 495
mp-wp_genesis 496 $category = get_category($cat_id);
mp-wp_genesis 497
mp-wp_genesis 498 if ( empty($category) || is_wp_error($category) )
mp-wp_genesis 499 return false;
mp-wp_genesis 500
mp-wp_genesis 501 if ( empty($feed) )
mp-wp_genesis 502 $feed = get_default_feed();
mp-wp_genesis 503
mp-wp_genesis 504 $permalink_structure = get_option('permalink_structure');
mp-wp_genesis 505
mp-wp_genesis 506 if ( '' == $permalink_structure ) {
mp-wp_genesis 507 $link = get_option('home') . "?feed=$feed&amp;cat=" . $cat_id;
mp-wp_genesis 508 } else {
mp-wp_genesis 509 $link = get_category_link($cat_id);
mp-wp_genesis 510 if( $feed == get_default_feed() )
mp-wp_genesis 511 $feed_link = 'feed';
mp-wp_genesis 512 else
mp-wp_genesis 513 $feed_link = "feed/$feed";
mp-wp_genesis 514
mp-wp_genesis 515 $link = trailingslashit($link) . user_trailingslashit($feed_link, 'feed');
mp-wp_genesis 516 }
mp-wp_genesis 517
mp-wp_genesis 518 $link = apply_filters('category_feed_link', $link, $feed);
mp-wp_genesis 519
mp-wp_genesis 520 return $link;
mp-wp_genesis 521 }
mp-wp_genesis 522
mp-wp_genesis 523 /**
mp-wp_genesis 524 * Retrieve permalink for feed of tag.
mp-wp_genesis 525 *
mp-wp_genesis 526 * @since 2.3.0
mp-wp_genesis 527 *
mp-wp_genesis 528 * @param int $tag_id Tag ID.
mp-wp_genesis 529 * @param string $feed Optional. Feed type.
mp-wp_genesis 530 * @return string
mp-wp_genesis 531 */
mp-wp_genesis 532 function get_tag_feed_link($tag_id, $feed = '') {
mp-wp_genesis 533 $tag_id = (int) $tag_id;
mp-wp_genesis 534
mp-wp_genesis 535 $tag = get_tag($tag_id);
mp-wp_genesis 536
mp-wp_genesis 537 if ( empty($tag) || is_wp_error($tag) )
mp-wp_genesis 538 return false;
mp-wp_genesis 539
mp-wp_genesis 540 $permalink_structure = get_option('permalink_structure');
mp-wp_genesis 541
mp-wp_genesis 542 if ( empty($feed) )
mp-wp_genesis 543 $feed = get_default_feed();
mp-wp_genesis 544
mp-wp_genesis 545 if ( '' == $permalink_structure ) {
mp-wp_genesis 546 $link = get_option('home') . "?feed=$feed&amp;tag=" . $tag->slug;
mp-wp_genesis 547 } else {
mp-wp_genesis 548 $link = get_tag_link($tag->term_id);
mp-wp_genesis 549 if ( $feed == get_default_feed() )
mp-wp_genesis 550 $feed_link = 'feed';
mp-wp_genesis 551 else
mp-wp_genesis 552 $feed_link = "feed/$feed";
mp-wp_genesis 553 $link = trailingslashit($link) . user_trailingslashit($feed_link, 'feed');
mp-wp_genesis 554 }
mp-wp_genesis 555
mp-wp_genesis 556 $link = apply_filters('tag_feed_link', $link, $feed);
mp-wp_genesis 557
mp-wp_genesis 558 return $link;
mp-wp_genesis 559 }
mp-wp_genesis 560
mp-wp_genesis 561 /**
mp-wp_genesis 562 * Retrieve edit tag link.
mp-wp_genesis 563 *
mp-wp_genesis 564 * @since 2.7.0
mp-wp_genesis 565 *
mp-wp_genesis 566 * @param int $tag_id Tag ID
mp-wp_genesis 567 * @return string
mp-wp_genesis 568 */
mp-wp_genesis 569 function get_edit_tag_link( $tag_id = 0 ) {
mp-wp_genesis 570 $tag = get_term($tag_id, 'post_tag');
mp-wp_genesis 571
mp-wp_genesis 572 if ( !current_user_can('manage_categories') )
mp-wp_genesis 573 return;
mp-wp_genesis 574
mp-wp_genesis 575 $location = admin_url('edit-tags.php?action=edit&amp;tag_ID=') . $tag->term_id;
mp-wp_genesis 576 return apply_filters( 'get_edit_tag_link', $location );
mp-wp_genesis 577 }
mp-wp_genesis 578
mp-wp_genesis 579 /**
mp-wp_genesis 580 * Display or retrieve edit tag link with formatting.
mp-wp_genesis 581 *
mp-wp_genesis 582 * @since 2.7.0
mp-wp_genesis 583 *
mp-wp_genesis 584 * @param string $link Optional. Anchor text.
mp-wp_genesis 585 * @param string $before Optional. Display before edit link.
mp-wp_genesis 586 * @param string $after Optional. Display after edit link.
mp-wp_genesis 587 * @param int|object $tag Tag object or ID
mp-wp_genesis 588 * @return string|null HTML content, if $echo is set to false.
mp-wp_genesis 589 */
mp-wp_genesis 590 function edit_tag_link( $link = '', $before = '', $after = '', $tag = null ) {
mp-wp_genesis 591 $tag = get_term($tag, 'post_tag');
mp-wp_genesis 592
mp-wp_genesis 593 if ( !current_user_can('manage_categories') )
mp-wp_genesis 594 return;
mp-wp_genesis 595
mp-wp_genesis 596 if ( empty($link) )
mp-wp_genesis 597 $link = __('Edit This');
mp-wp_genesis 598
mp-wp_genesis 599 $link = '<a href="' . get_edit_tag_link( $tag->term_id ) . '" title="' . __( 'Edit tag' ) . '">' . $link . '</a>';
mp-wp_genesis 600 echo $before . apply_filters( 'edit_tag_link', $link, $tag->term_id ) . $after;
mp-wp_genesis 601 }
mp-wp_genesis 602
mp-wp_genesis 603 /**
mp-wp_genesis 604 * Retrieve the permalink for the feed of the search results.
mp-wp_genesis 605 *
mp-wp_genesis 606 * @since 2.5.0
mp-wp_genesis 607 *
mp-wp_genesis 608 * @param string $search_query Optional. Search query.
mp-wp_genesis 609 * @param string $feed Optional. Feed type.
mp-wp_genesis 610 * @return string
mp-wp_genesis 611 */
mp-wp_genesis 612 function get_search_feed_link($search_query = '', $feed = '') {
mp-wp_genesis 613 if ( empty($search_query) )
mp-wp_genesis 614 $search = attribute_escape(get_search_query());
mp-wp_genesis 615 else
mp-wp_genesis 616 $search = attribute_escape(stripslashes($search_query));
mp-wp_genesis 617
mp-wp_genesis 618 if ( empty($feed) )
mp-wp_genesis 619 $feed = get_default_feed();
mp-wp_genesis 620
mp-wp_genesis 621 $link = get_option('home') . "?s=$search&amp;feed=$feed";
mp-wp_genesis 622
mp-wp_genesis 623 $link = apply_filters('search_feed_link', $link);
mp-wp_genesis 624
mp-wp_genesis 625 return $link;
mp-wp_genesis 626 }
mp-wp_genesis 627
mp-wp_genesis 628 /**
mp-wp_genesis 629 * Retrieve the permalink for the comments feed of the search results.
mp-wp_genesis 630 *
mp-wp_genesis 631 * @since 2.5.0
mp-wp_genesis 632 *
mp-wp_genesis 633 * @param string $search_query Optional. Search query.
mp-wp_genesis 634 * @param string $feed Optional. Feed type.
mp-wp_genesis 635 * @return string
mp-wp_genesis 636 */
mp-wp_genesis 637 function get_search_comments_feed_link($search_query = '', $feed = '') {
mp-wp_genesis 638 if ( empty($search_query) )
mp-wp_genesis 639 $search = attribute_escape(get_search_query());
mp-wp_genesis 640 else
mp-wp_genesis 641 $search = attribute_escape(stripslashes($search_query));
mp-wp_genesis 642
mp-wp_genesis 643 if ( empty($feed) )
mp-wp_genesis 644 $feed = get_default_feed();
mp-wp_genesis 645
mp-wp_genesis 646 $link = get_option('home') . "?s=$search&amp;feed=comments-$feed";
mp-wp_genesis 647
mp-wp_genesis 648 $link = apply_filters('search_feed_link', $link);
mp-wp_genesis 649
mp-wp_genesis 650 return $link;
mp-wp_genesis 651 }
mp-wp_genesis 652
mp-wp_genesis 653 /**
mp-wp_genesis 654 * Retrieve edit posts link for post.
mp-wp_genesis 655 *
mp-wp_genesis 656 * Can be used within the WordPress loop or outside of it. Can be used with
mp-wp_genesis 657 * pages, posts, attachments, and revisions.
mp-wp_genesis 658 *
mp-wp_genesis 659 * @since 2.3.0
mp-wp_genesis 660 *
mp-wp_genesis 661 * @param int $id Optional. Post ID.
mp-wp_genesis 662 * @param string $context Optional, default to display. How to write the '&', defaults to '&amp;'.
mp-wp_genesis 663 * @return string
mp-wp_genesis 664 */
mp-wp_genesis 665 function get_edit_post_link( $id = 0, $context = 'display' ) {
mp-wp_genesis 666 if ( !$post = &get_post( $id ) )
mp-wp_genesis 667 return;
mp-wp_genesis 668
mp-wp_genesis 669 if ( 'display' == $context )
mp-wp_genesis 670 $action = 'action=edit&amp;';
mp-wp_genesis 671 else
mp-wp_genesis 672 $action = 'action=edit&';
mp-wp_genesis 673
mp-wp_genesis 674 switch ( $post->post_type ) :
mp-wp_genesis 675 case 'page' :
mp-wp_genesis 676 if ( !current_user_can( 'edit_page', $post->ID ) )
mp-wp_genesis 677 return;
mp-wp_genesis 678 $file = 'page';
mp-wp_genesis 679 $var = 'post';
mp-wp_genesis 680 break;
mp-wp_genesis 681 case 'attachment' :
mp-wp_genesis 682 if ( !current_user_can( 'edit_post', $post->ID ) )
mp-wp_genesis 683 return;
mp-wp_genesis 684 $file = 'media';
mp-wp_genesis 685 $var = 'attachment_id';
mp-wp_genesis 686 break;
mp-wp_genesis 687 case 'revision' :
mp-wp_genesis 688 if ( !current_user_can( 'edit_post', $post->ID ) )
mp-wp_genesis 689 return;
mp-wp_genesis 690 $file = 'revision';
mp-wp_genesis 691 $var = 'revision';
mp-wp_genesis 692 $action = '';
mp-wp_genesis 693 break;
mp-wp_genesis 694 default :
mp-wp_genesis 695 if ( !current_user_can( 'edit_post', $post->ID ) )
mp-wp_genesis 696 return;
mp-wp_genesis 697 $file = 'post';
mp-wp_genesis 698 $var = 'post';
mp-wp_genesis 699 break;
mp-wp_genesis 700 endswitch;
mp-wp_genesis 701
mp-wp_genesis 702 return apply_filters( 'get_edit_post_link', admin_url("$file.php?{$action}$var=$post->ID"), $post->ID, $context );
mp-wp_genesis 703 }
mp-wp_genesis 704
mp-wp_genesis 705 /**
mp-wp_genesis 706 * Retrieve edit posts link for post.
mp-wp_genesis 707 *
mp-wp_genesis 708 * @since 1.0.0
mp-wp_genesis 709 *
mp-wp_genesis 710 * @param string $link Optional. Anchor text.
mp-wp_genesis 711 * @param string $before Optional. Display before edit link.
mp-wp_genesis 712 * @param string $after Optional. Display after edit link.
mp-wp_genesis 713 */
mp-wp_genesis 714 function edit_post_link( $link = 'Edit This', $before = '', $after = '' ) {
mp-wp_genesis 715 global $post;
mp-wp_genesis 716
mp-wp_genesis 717 if ( $post->post_type == 'page' ) {
mp-wp_genesis 718 if ( !current_user_can( 'edit_page', $post->ID ) )
mp-wp_genesis 719 return;
mp-wp_genesis 720 } else {
mp-wp_genesis 721 if ( !current_user_can( 'edit_post', $post->ID ) )
mp-wp_genesis 722 return;
mp-wp_genesis 723 }
mp-wp_genesis 724
mp-wp_genesis 725 $link = '<a href="' . get_edit_post_link( $post->ID ) . '" title="' . attribute_escape( __( 'Edit post' ) ) . '">' . $link . '</a>';
mp-wp_genesis 726 echo $before . apply_filters( 'edit_post_link', $link, $post->ID ) . $after;
mp-wp_genesis 727 }
mp-wp_genesis 728
mp-wp_genesis 729 /**
mp-wp_genesis 730 * Retrieve edit comment link.
mp-wp_genesis 731 *
mp-wp_genesis 732 * @since 2.3.0
mp-wp_genesis 733 *
mp-wp_genesis 734 * @param int $comment_id Optional. Comment ID.
mp-wp_genesis 735 * @return string
mp-wp_genesis 736 */
mp-wp_genesis 737 function get_edit_comment_link( $comment_id = 0 ) {
mp-wp_genesis 738 $comment = &get_comment( $comment_id );
mp-wp_genesis 739 $post = &get_post( $comment->comment_post_ID );
mp-wp_genesis 740
mp-wp_genesis 741 if ( $post->post_type == 'page' ) {
mp-wp_genesis 742 if ( !current_user_can( 'edit_page', $post->ID ) )
mp-wp_genesis 743 return;
mp-wp_genesis 744 } else {
mp-wp_genesis 745 if ( !current_user_can( 'edit_post', $post->ID ) )
mp-wp_genesis 746 return;
mp-wp_genesis 747 }
mp-wp_genesis 748
mp-wp_genesis 749 $location = admin_url('comment.php?action=editcomment&amp;c=') . $comment->comment_ID;
mp-wp_genesis 750 return apply_filters( 'get_edit_comment_link', $location );
mp-wp_genesis 751 }
mp-wp_genesis 752
mp-wp_genesis 753 /**
mp-wp_genesis 754 * Display or retrieve edit comment link with formatting.
mp-wp_genesis 755 *
mp-wp_genesis 756 * @since 1.0.0
mp-wp_genesis 757 *
mp-wp_genesis 758 * @param string $link Optional. Anchor text.
mp-wp_genesis 759 * @param string $before Optional. Display before edit link.
mp-wp_genesis 760 * @param string $after Optional. Display after edit link.
mp-wp_genesis 761 * @return string|null HTML content, if $echo is set to false.
mp-wp_genesis 762 */
mp-wp_genesis 763 function edit_comment_link( $link = 'Edit This', $before = '', $after = '' ) {
mp-wp_genesis 764 global $comment, $post;
mp-wp_genesis 765
mp-wp_genesis 766 if ( $post->post_type == 'attachment' ) {
mp-wp_genesis 767 } elseif ( $post->post_type == 'page' ) {
mp-wp_genesis 768 if ( !current_user_can( 'edit_page', $post->ID ) )
mp-wp_genesis 769 return;
mp-wp_genesis 770 } else {
mp-wp_genesis 771 if ( !current_user_can( 'edit_post', $post->ID ) )
mp-wp_genesis 772 return;
mp-wp_genesis 773 }
mp-wp_genesis 774
mp-wp_genesis 775 $link = '<a href="' . get_edit_comment_link( $comment->comment_ID ) . '" title="' . __( 'Edit comment' ) . '">' . $link . '</a>';
mp-wp_genesis 776 echo $before . apply_filters( 'edit_comment_link', $link, $comment->comment_ID ) . $after;
mp-wp_genesis 777 }
mp-wp_genesis 778
mp-wp_genesis 779 /**
mp-wp_genesis 780 * Display edit bookmark (literally a URL external to blog) link.
mp-wp_genesis 781 *
mp-wp_genesis 782 * @since 2.7.0
mp-wp_genesis 783 *
mp-wp_genesis 784 * @param int $link Optional. Bookmark ID.
mp-wp_genesis 785 * @return string
mp-wp_genesis 786 */
mp-wp_genesis 787 function get_edit_bookmark_link( $link = 0 ) {
mp-wp_genesis 788 $link = get_bookmark( $link );
mp-wp_genesis 789
mp-wp_genesis 790 if ( !current_user_can('manage_links') )
mp-wp_genesis 791 return;
mp-wp_genesis 792
mp-wp_genesis 793 $location = admin_url('link.php?action=edit&amp;link_id=') . $link->link_id;
mp-wp_genesis 794 return apply_filters( 'get_edit_bookmark_link', $location, $link->link_id );
mp-wp_genesis 795 }
mp-wp_genesis 796
mp-wp_genesis 797 /**
mp-wp_genesis 798 * Display edit bookmark (literally a URL external to blog) link anchor content.
mp-wp_genesis 799 *
mp-wp_genesis 800 * @since 2.7.0
mp-wp_genesis 801 *
mp-wp_genesis 802 * @param string $link Optional. Anchor text.
mp-wp_genesis 803 * @param string $before Optional. Display before edit link.
mp-wp_genesis 804 * @param string $after Optional. Display after edit link.
mp-wp_genesis 805 * @param int $bookmark Optional. Bookmark ID.
mp-wp_genesis 806 */
mp-wp_genesis 807 function edit_bookmark_link( $link = '', $before = '', $after = '', $bookmark = null ) {
mp-wp_genesis 808 $bookmark = get_bookmark($bookmark);
mp-wp_genesis 809
mp-wp_genesis 810 if ( !current_user_can('manage_links') )
mp-wp_genesis 811 return;
mp-wp_genesis 812
mp-wp_genesis 813 if ( empty($link) )
mp-wp_genesis 814 $link = __('Edit This');
mp-wp_genesis 815
mp-wp_genesis 816 $link = '<a href="' . get_edit_bookmark_link( $link ) . '" title="' . __( 'Edit link' ) . '">' . $link . '</a>';
mp-wp_genesis 817 echo $before . apply_filters( 'edit_bookmark_link', $link, $bookmark->link_id ) . $after;
mp-wp_genesis 818 }
mp-wp_genesis 819
mp-wp_genesis 820 // Navigation links
mp-wp_genesis 821
mp-wp_genesis 822 /**
mp-wp_genesis 823 * Retrieve previous post link that is adjacent to current post.
mp-wp_genesis 824 *
mp-wp_genesis 825 * @since 1.5.0
mp-wp_genesis 826 *
mp-wp_genesis 827 * @param bool $in_same_cat Optional. Whether link should be in same category.
mp-wp_genesis 828 * @param string $excluded_categories Optional. Excluded categories IDs.
mp-wp_genesis 829 * @return string
mp-wp_genesis 830 */
mp-wp_genesis 831 function get_previous_post($in_same_cat = false, $excluded_categories = '') {
mp-wp_genesis 832 return get_adjacent_post($in_same_cat, $excluded_categories);
mp-wp_genesis 833 }
mp-wp_genesis 834
mp-wp_genesis 835 /**
mp-wp_genesis 836 * Retrieve next post link that is adjacent to current post.
mp-wp_genesis 837 *
mp-wp_genesis 838 * @since 1.5.0
mp-wp_genesis 839 *
mp-wp_genesis 840 * @param bool $in_same_cat Optional. Whether link should be in same category.
mp-wp_genesis 841 * @param string $excluded_categories Optional. Excluded categories IDs.
mp-wp_genesis 842 * @return string
mp-wp_genesis 843 */
mp-wp_genesis 844 function get_next_post($in_same_cat = false, $excluded_categories = '') {
mp-wp_genesis 845 return get_adjacent_post($in_same_cat, $excluded_categories, false);
mp-wp_genesis 846 }
mp-wp_genesis 847
mp-wp_genesis 848 /**
mp-wp_genesis 849 * Retrieve adjacent post link.
mp-wp_genesis 850 *
mp-wp_genesis 851 * Can either be next or previous post link.
mp-wp_genesis 852 *
mp-wp_genesis 853 * @since 2.5.0
mp-wp_genesis 854 *
mp-wp_genesis 855 * @param bool $in_same_cat Optional. Whether link should be in same category.
mp-wp_genesis 856 * @param string $excluded_categories Optional. Excluded categories IDs.
mp-wp_genesis 857 * @param bool $previous Optional. Whether to retrieve previous post.
mp-wp_genesis 858 * @return string
mp-wp_genesis 859 */
mp-wp_genesis 860 function get_adjacent_post($in_same_cat = false, $excluded_categories = '', $previous = true) {
mp-wp_genesis 861 global $post, $wpdb;
mp-wp_genesis 862
mp-wp_genesis 863 if( empty($post) || !is_single() || is_attachment() )
mp-wp_genesis 864 return null;
mp-wp_genesis 865
mp-wp_genesis 866 $current_post_date = $post->post_date;
mp-wp_genesis 867
mp-wp_genesis 868 $join = '';
mp-wp_genesis 869 $posts_in_ex_cats_sql = '';
mp-wp_genesis 870 if ( $in_same_cat || !empty($excluded_categories) ) {
mp-wp_genesis 871 $join = " INNER JOIN $wpdb->term_relationships AS tr ON p.ID = tr.object_id INNER JOIN $wpdb->term_taxonomy tt ON tr.term_taxonomy_id = tt.term_taxonomy_id";
mp-wp_genesis 872
mp-wp_genesis 873 if ( $in_same_cat ) {
mp-wp_genesis 874 $cat_array = wp_get_object_terms($post->ID, 'category', 'fields=ids');
mp-wp_genesis 875 $join .= " AND tt.taxonomy = 'category' AND tt.term_id IN (" . implode(',', $cat_array) . ")";
mp-wp_genesis 876 }
mp-wp_genesis 877
mp-wp_genesis 878 $posts_in_ex_cats_sql = "AND tt.taxonomy = 'category'";
mp-wp_genesis 879 if ( !empty($excluded_categories) ) {
mp-wp_genesis 880 $excluded_categories = array_map('intval', explode(' and ', $excluded_categories));
mp-wp_genesis 881 if ( !empty($cat_array) ) {
mp-wp_genesis 882 $excluded_categories = array_diff($excluded_categories, $cat_array);
mp-wp_genesis 883 $posts_in_ex_cats_sql = '';
mp-wp_genesis 884 }
mp-wp_genesis 885
mp-wp_genesis 886 if ( !empty($excluded_categories) ) {
mp-wp_genesis 887 $posts_in_ex_cats_sql = " AND tt.taxonomy = 'category' AND tt.term_id NOT IN (" . implode($excluded_categories, ',') . ')';
mp-wp_genesis 888 }
mp-wp_genesis 889 }
mp-wp_genesis 890 }
mp-wp_genesis 891
mp-wp_genesis 892 $adjacent = $previous ? 'previous' : 'next';
mp-wp_genesis 893 $op = $previous ? '<' : '>';
mp-wp_genesis 894 $order = $previous ? 'DESC' : 'ASC';
mp-wp_genesis 895
mp-wp_genesis 896 $join = apply_filters( "get_{$adjacent}_post_join", $join, $in_same_cat, $excluded_categories );
mp-wp_genesis 897 $where = apply_filters( "get_{$adjacent}_post_where", $wpdb->prepare("WHERE p.post_date $op %s AND p.post_type = 'post' AND p.post_status = 'publish' $posts_in_ex_cats_sql", $current_post_date), $in_same_cat, $excluded_categories );
mp-wp_genesis 898 $sort = apply_filters( "get_{$adjacent}_post_sort", "ORDER BY p.post_date $order LIMIT 1" );
mp-wp_genesis 899
mp-wp_genesis 900 return $wpdb->get_row("SELECT p.* FROM $wpdb->posts AS p $join $where $sort");
mp-wp_genesis 901 }
mp-wp_genesis 902
mp-wp_genesis 903 /**
mp-wp_genesis 904 * Display previous post link that is adjacent to the current post.
mp-wp_genesis 905 *
mp-wp_genesis 906 * @since 1.5.0
mp-wp_genesis 907 *
mp-wp_genesis 908 * @param string $format Optional. Link anchor format.
mp-wp_genesis 909 * @param string $link Optional. Link permalink format.
mp-wp_genesis 910 * @param bool $in_same_cat Optional. Whether link should be in same category.
mp-wp_genesis 911 * @param string $excluded_categories Optional. Excluded categories IDs.
mp-wp_genesis 912 */
mp-wp_genesis 913 function previous_post_link($format='&laquo; %link', $link='%title', $in_same_cat = false, $excluded_categories = '') {
mp-wp_genesis 914 adjacent_post_link($format, $link, $in_same_cat, $excluded_categories, true);
mp-wp_genesis 915 }
mp-wp_genesis 916
mp-wp_genesis 917 /**
mp-wp_genesis 918 * Display next post link that is adjacent to the current post.
mp-wp_genesis 919 *
mp-wp_genesis 920 * @since 1.5.0
mp-wp_genesis 921 *
mp-wp_genesis 922 * @param string $format Optional. Link anchor format.
mp-wp_genesis 923 * @param string $link Optional. Link permalink format.
mp-wp_genesis 924 * @param bool $in_same_cat Optional. Whether link should be in same category.
mp-wp_genesis 925 * @param string $excluded_categories Optional. Excluded categories IDs.
mp-wp_genesis 926 */
mp-wp_genesis 927 function next_post_link($format='%link &raquo;', $link='%title', $in_same_cat = false, $excluded_categories = '') {
mp-wp_genesis 928 adjacent_post_link($format, $link, $in_same_cat, $excluded_categories, false);
mp-wp_genesis 929 }
mp-wp_genesis 930
mp-wp_genesis 931 /**
mp-wp_genesis 932 * Display adjacent post link.
mp-wp_genesis 933 *
mp-wp_genesis 934 * Can be either next post link or previous.
mp-wp_genesis 935 *
mp-wp_genesis 936 * @since 2.5.0
mp-wp_genesis 937 *
mp-wp_genesis 938 * @param string $format Link anchor format.
mp-wp_genesis 939 * @param string $link Link permalink format.
mp-wp_genesis 940 * @param bool $in_same_cat Optional. Whether link should be in same category.
mp-wp_genesis 941 * @param string $excluded_categories Optional. Excluded categories IDs.
mp-wp_genesis 942 * @param bool $previous Optional, default is true. Whether display link to previous post.
mp-wp_genesis 943 */
mp-wp_genesis 944 function adjacent_post_link($format, $link, $in_same_cat = false, $excluded_categories = '', $previous = true) {
mp-wp_genesis 945 if ( $previous && is_attachment() )
mp-wp_genesis 946 $post = & get_post($GLOBALS['post']->post_parent);
mp-wp_genesis 947 else
mp-wp_genesis 948 $post = get_adjacent_post($in_same_cat, $excluded_categories, $previous);
mp-wp_genesis 949
mp-wp_genesis 950 if ( !$post )
mp-wp_genesis 951 return;
mp-wp_genesis 952
mp-wp_genesis 953 $title = $post->post_title;
mp-wp_genesis 954
mp-wp_genesis 955 if ( empty($post->post_title) )
mp-wp_genesis 956 $title = $previous ? __('Previous Post') : __('Next Post');
mp-wp_genesis 957
mp-wp_genesis 958 $title = apply_filters('the_title', $title, $post);
mp-wp_genesis 959 $date = mysql2date(get_option('date_format'), $post->post_date);
mp-wp_genesis 960
mp-wp_genesis 961 $string = '<a href="'.get_permalink($post).'">';
mp-wp_genesis 962 $link = str_replace('%title', $title, $link);
mp-wp_genesis 963 $link = str_replace('%date', $date, $link);
mp-wp_genesis 964 $link = $string . $link . '</a>';
mp-wp_genesis 965
mp-wp_genesis 966 $format = str_replace('%link', $link, $format);
mp-wp_genesis 967
mp-wp_genesis 968 $adjacent = $previous ? 'previous' : 'next';
mp-wp_genesis 969 echo apply_filters( "{$adjacent}_post_link", $format, $link );
mp-wp_genesis 970 }
mp-wp_genesis 971
mp-wp_genesis 972 /**
mp-wp_genesis 973 * Retrieve get links for page numbers.
mp-wp_genesis 974 *
mp-wp_genesis 975 * @since 1.5.0
mp-wp_genesis 976 *
mp-wp_genesis 977 * @param int $pagenum Optional. Page ID.
mp-wp_genesis 978 * @return string
mp-wp_genesis 979 */
mp-wp_genesis 980 function get_pagenum_link($pagenum = 1) {
mp-wp_genesis 981 global $wp_rewrite;
mp-wp_genesis 982
mp-wp_genesis 983 $pagenum = (int) $pagenum;
mp-wp_genesis 984
mp-wp_genesis 985 $request = remove_query_arg( 'paged' );
mp-wp_genesis 986
mp-wp_genesis 987 $home_root = parse_url(get_option('home'));
mp-wp_genesis 988 $home_root = ( isset($home_root['path']) ) ? $home_root['path'] : '';
mp-wp_genesis 989 $home_root = preg_quote( trailingslashit( $home_root ), '|' );
mp-wp_genesis 990
mp-wp_genesis 991 $request = preg_replace('|^'. $home_root . '|', '', $request);
mp-wp_genesis 992 $request = preg_replace('|^/+|', '', $request);
mp-wp_genesis 993
mp-wp_genesis 994 if ( !$wp_rewrite->using_permalinks() || is_admin() ) {
mp-wp_genesis 995 $base = trailingslashit( get_bloginfo( 'home' ) );
mp-wp_genesis 996
mp-wp_genesis 997 if ( $pagenum > 1 ) {
mp-wp_genesis 998 $result = add_query_arg( 'paged', $pagenum, $base . $request );
mp-wp_genesis 999 } else {
mp-wp_genesis 1000 $result = $base . $request;
mp-wp_genesis 1001 }
mp-wp_genesis 1002 } else {
mp-wp_genesis 1003 $qs_regex = '|\?.*?$|';
mp-wp_genesis 1004 preg_match( $qs_regex, $request, $qs_match );
mp-wp_genesis 1005
mp-wp_genesis 1006 if ( !empty( $qs_match[0] ) ) {
mp-wp_genesis 1007 $query_string = $qs_match[0];
mp-wp_genesis 1008 $request = preg_replace( $qs_regex, '', $request );
mp-wp_genesis 1009 } else {
mp-wp_genesis 1010 $query_string = '';
mp-wp_genesis 1011 }
mp-wp_genesis 1012
mp-wp_genesis 1013 $request = preg_replace( '|page/\d+/?$|', '', $request);
mp-wp_genesis 1014 $request = preg_replace( '|^index\.php|', '', $request);
mp-wp_genesis 1015 $request = ltrim($request, '/');
mp-wp_genesis 1016
mp-wp_genesis 1017 $base = trailingslashit( get_bloginfo( 'url' ) );
mp-wp_genesis 1018
mp-wp_genesis 1019 if ( $wp_rewrite->using_index_permalinks() && ( $pagenum > 1 || '' != $request ) )
mp-wp_genesis 1020 $base .= 'index.php/';
mp-wp_genesis 1021
mp-wp_genesis 1022 if ( $pagenum > 1 ) {
mp-wp_genesis 1023 $request = ( ( !empty( $request ) ) ? trailingslashit( $request ) : $request ) . user_trailingslashit( 'page/' . $pagenum, 'paged' );
mp-wp_genesis 1024 }
mp-wp_genesis 1025
mp-wp_genesis 1026 $result = $base . $request . $query_string;
mp-wp_genesis 1027 }
mp-wp_genesis 1028
mp-wp_genesis 1029 $result = apply_filters('get_pagenum_link', $result);
mp-wp_genesis 1030
mp-wp_genesis 1031 return $result;
mp-wp_genesis 1032 }
mp-wp_genesis 1033
mp-wp_genesis 1034 /**
mp-wp_genesis 1035 * Retrieve next posts pages link.
mp-wp_genesis 1036 *
mp-wp_genesis 1037 * Backported from 2.1.3 to 2.0.10.
mp-wp_genesis 1038 *
mp-wp_genesis 1039 * @since 2.0.10
mp-wp_genesis 1040 *
mp-wp_genesis 1041 * @param int $max_page Optional. Max pages.
mp-wp_genesis 1042 * @return string
mp-wp_genesis 1043 */
mp-wp_genesis 1044 function get_next_posts_page_link($max_page = 0) {
mp-wp_genesis 1045 global $paged;
mp-wp_genesis 1046
mp-wp_genesis 1047 if ( !is_single() ) {
mp-wp_genesis 1048 if ( !$paged )
mp-wp_genesis 1049 $paged = 1;
mp-wp_genesis 1050 $nextpage = intval($paged) + 1;
mp-wp_genesis 1051 if ( !$max_page || $max_page >= $nextpage )
mp-wp_genesis 1052 return get_pagenum_link($nextpage);
mp-wp_genesis 1053 }
mp-wp_genesis 1054 }
mp-wp_genesis 1055
mp-wp_genesis 1056 /**
mp-wp_genesis 1057 * Display or return the next posts pages link.
mp-wp_genesis 1058 *
mp-wp_genesis 1059 * @since 0.71
mp-wp_genesis 1060 *
mp-wp_genesis 1061 * @param int $max_page Optional. Max pages.
mp-wp_genesis 1062 * @param boolean $echo Optional. Echo or return;
mp-wp_genesis 1063 */
mp-wp_genesis 1064 function next_posts( $max_page = 0, $echo = true ) {
mp-wp_genesis 1065 $output = clean_url( get_next_posts_page_link( $max_page ) );
mp-wp_genesis 1066
mp-wp_genesis 1067 if ( $echo )
mp-wp_genesis 1068 echo $output;
mp-wp_genesis 1069 else
mp-wp_genesis 1070 return $output;
mp-wp_genesis 1071 }
mp-wp_genesis 1072
mp-wp_genesis 1073 /**
mp-wp_genesis 1074 * Return the next posts pages link.
mp-wp_genesis 1075 *
mp-wp_genesis 1076 * @since 2.7.0
mp-wp_genesis 1077 *
mp-wp_genesis 1078 * @param string $label Content for link text.
mp-wp_genesis 1079 * @param int $max_page Optional. Max pages.
mp-wp_genesis 1080 * @return string|null
mp-wp_genesis 1081 */
mp-wp_genesis 1082 function get_next_posts_link( $label = 'Next Page &raquo;', $max_page = 0 ) {
mp-wp_genesis 1083 global $paged, $wp_query;
mp-wp_genesis 1084
mp-wp_genesis 1085 if ( !$max_page ) {
mp-wp_genesis 1086 $max_page = $wp_query->max_num_pages;
mp-wp_genesis 1087 }
mp-wp_genesis 1088
mp-wp_genesis 1089 if ( !$paged )
mp-wp_genesis 1090 $paged = 1;
mp-wp_genesis 1091
mp-wp_genesis 1092 $nextpage = intval($paged) + 1;
mp-wp_genesis 1093
mp-wp_genesis 1094 if ( !is_single() && ( empty($paged) || $nextpage <= $max_page) ) {
mp-wp_genesis 1095 $attr = apply_filters( 'next_posts_link_attributes', '' );
mp-wp_genesis 1096 return '<a href="' . next_posts( $max_page, false ) . "\" $attr>". preg_replace('/&([^#])(?![a-z]{1,8};)/', '&#038;$1', $label) .'</a>';
mp-wp_genesis 1097 }
mp-wp_genesis 1098 }
mp-wp_genesis 1099
mp-wp_genesis 1100 /**
mp-wp_genesis 1101 * Display the next posts pages link.
mp-wp_genesis 1102 *
mp-wp_genesis 1103 * @since 0.71
mp-wp_genesis 1104 * @uses get_next_posts_link()
mp-wp_genesis 1105 *
mp-wp_genesis 1106 * @param string $label Content for link text.
mp-wp_genesis 1107 * @param int $max_page Optional. Max pages.
mp-wp_genesis 1108 */
mp-wp_genesis 1109 function next_posts_link( $label = 'Next Page &raquo;', $max_page = 0 ) {
mp-wp_genesis 1110 echo get_next_posts_link( $label, $max_page );
mp-wp_genesis 1111 }
mp-wp_genesis 1112
mp-wp_genesis 1113 /**
mp-wp_genesis 1114 * Retrieve previous post pages link.
mp-wp_genesis 1115 *
mp-wp_genesis 1116 * Will only return string, if not on a single page or post.
mp-wp_genesis 1117 *
mp-wp_genesis 1118 * Backported to 2.0.10 from 2.1.3.
mp-wp_genesis 1119 *
mp-wp_genesis 1120 * @since 2.0.10
mp-wp_genesis 1121 *
mp-wp_genesis 1122 * @return string|null
mp-wp_genesis 1123 */
mp-wp_genesis 1124 function get_previous_posts_page_link() {
mp-wp_genesis 1125 global $paged;
mp-wp_genesis 1126
mp-wp_genesis 1127 if ( !is_single() ) {
mp-wp_genesis 1128 $nextpage = intval($paged) - 1;
mp-wp_genesis 1129 if ( $nextpage < 1 )
mp-wp_genesis 1130 $nextpage = 1;
mp-wp_genesis 1131 return get_pagenum_link($nextpage);
mp-wp_genesis 1132 }
mp-wp_genesis 1133 }
mp-wp_genesis 1134
mp-wp_genesis 1135 /**
mp-wp_genesis 1136 * Display or return the previous posts pages link.
mp-wp_genesis 1137 *
mp-wp_genesis 1138 * @since 0.71
mp-wp_genesis 1139 *
mp-wp_genesis 1140 * @param boolean $echo Optional. Echo or return;
mp-wp_genesis 1141 */
mp-wp_genesis 1142 function previous_posts( $echo = true ) {
mp-wp_genesis 1143 $output = clean_url( get_previous_posts_page_link() );
mp-wp_genesis 1144
mp-wp_genesis 1145 if ( $echo )
mp-wp_genesis 1146 echo $output;
mp-wp_genesis 1147 else
mp-wp_genesis 1148 return $output;
mp-wp_genesis 1149 }
mp-wp_genesis 1150
mp-wp_genesis 1151 /**
mp-wp_genesis 1152 * Return the previous posts pages link.
mp-wp_genesis 1153 *
mp-wp_genesis 1154 * @since 2.7.0
mp-wp_genesis 1155 *
mp-wp_genesis 1156 * @param string $label Optional. Previous page link text.
mp-wp_genesis 1157 * @return string|null
mp-wp_genesis 1158 */
mp-wp_genesis 1159 function get_previous_posts_link( $label = '&laquo; Previous Page' ) {
mp-wp_genesis 1160 global $paged;
mp-wp_genesis 1161
mp-wp_genesis 1162 if ( !is_single() && $paged > 1 ) {
mp-wp_genesis 1163 $attr = apply_filters( 'previous_posts_link_attributes', '' );
mp-wp_genesis 1164 return '<a href="' . previous_posts( false ) . "\" $attr>". preg_replace( '/&([^#])(?![a-z]{1,8};)/', '&#038;$1', $label ) .'</a>';
mp-wp_genesis 1165 }
mp-wp_genesis 1166 }
mp-wp_genesis 1167
mp-wp_genesis 1168 /**
mp-wp_genesis 1169 * Display the previous posts page link.
mp-wp_genesis 1170 *
mp-wp_genesis 1171 * @since 0.71
mp-wp_genesis 1172 * @uses get_previous_posts_link()
mp-wp_genesis 1173 *
mp-wp_genesis 1174 * @param string $label Optional. Previous page link text.
mp-wp_genesis 1175 */
mp-wp_genesis 1176 function previous_posts_link( $label = '&laquo; Previous Page' ) {
mp-wp_genesis 1177 echo get_previous_posts_link( $label );
mp-wp_genesis 1178 }
mp-wp_genesis 1179
mp-wp_genesis 1180 /**
mp-wp_genesis 1181 * Display post pages link navigation for previous and next pages.
mp-wp_genesis 1182 *
mp-wp_genesis 1183 * @since 0.71
mp-wp_genesis 1184 *
mp-wp_genesis 1185 * @param string $sep Optional. Separator for posts navigation links.
mp-wp_genesis 1186 * @param string $prelabel Optional. Label for previous pages.
mp-wp_genesis 1187 * @param string $nxtlabel Optional Label for next pages.
mp-wp_genesis 1188 */
mp-wp_genesis 1189 function posts_nav_link( $sep = ' &#8212; ', $prelabel = '&laquo; Previous Page', $nxtlabel = 'Next Page &raquo;' ) {
mp-wp_genesis 1190 global $wp_query;
mp-wp_genesis 1191 if ( !is_singular() ) {
mp-wp_genesis 1192 $max_num_pages = $wp_query->max_num_pages;
mp-wp_genesis 1193 $paged = get_query_var('paged');
mp-wp_genesis 1194
mp-wp_genesis 1195 //only have sep if there's both prev and next results
mp-wp_genesis 1196 if ($paged < 2 || $paged >= $max_num_pages) {
mp-wp_genesis 1197 $sep = '';
mp-wp_genesis 1198 }
mp-wp_genesis 1199
mp-wp_genesis 1200 if ( $max_num_pages > 1 ) {
mp-wp_genesis 1201 previous_posts_link($prelabel);
mp-wp_genesis 1202 echo preg_replace('/&([^#])(?![a-z]{1,8};)/', '&#038;$1', $sep);
mp-wp_genesis 1203 next_posts_link($nxtlabel);
mp-wp_genesis 1204 }
mp-wp_genesis 1205 }
mp-wp_genesis 1206 }
mp-wp_genesis 1207
mp-wp_genesis 1208 /**
mp-wp_genesis 1209 * Retrieve page numbers links.
mp-wp_genesis 1210 *
mp-wp_genesis 1211 * @since 2.7.0
mp-wp_genesis 1212 *
mp-wp_genesis 1213 * @param int $pagenum Optional. Page number.
mp-wp_genesis 1214 * @return string
mp-wp_genesis 1215 */
mp-wp_genesis 1216 function get_comments_pagenum_link( $pagenum = 1, $max_page = 0 ) {
mp-wp_genesis 1217 global $post, $wp_rewrite;
mp-wp_genesis 1218
mp-wp_genesis 1219 $pagenum = (int) $pagenum;
mp-wp_genesis 1220
mp-wp_genesis 1221 $result = get_permalink( $post->ID );
mp-wp_genesis 1222
mp-wp_genesis 1223 if ( 'newest' == get_option('default_comments_page') ) {
mp-wp_genesis 1224 if ( $pagenum != $max_page ) {
mp-wp_genesis 1225 if ( $wp_rewrite->using_permalinks() )
mp-wp_genesis 1226 $result = user_trailingslashit( trailingslashit($result) . 'comment-page-' . $pagenum, 'commentpaged');
mp-wp_genesis 1227 else
mp-wp_genesis 1228 $result = add_query_arg( 'cpage', $pagenum, $result );
mp-wp_genesis 1229 }
mp-wp_genesis 1230 } elseif ( $pagenum > 1 ) {
mp-wp_genesis 1231 if ( $wp_rewrite->using_permalinks() )
mp-wp_genesis 1232 $result = user_trailingslashit( trailingslashit($result) . 'comment-page-' . $pagenum, 'commentpaged');
mp-wp_genesis 1233 else
mp-wp_genesis 1234 $result = add_query_arg( 'cpage', $pagenum, $result );
mp-wp_genesis 1235 }
mp-wp_genesis 1236
mp-wp_genesis 1237 $result .= '#comments';
mp-wp_genesis 1238
mp-wp_genesis 1239 $result = apply_filters('get_comments_pagenum_link', $result);
mp-wp_genesis 1240
mp-wp_genesis 1241 return $result;
mp-wp_genesis 1242 }
mp-wp_genesis 1243
mp-wp_genesis 1244 /**
mp-wp_genesis 1245 * Display link to next comments pages.
mp-wp_genesis 1246 *
mp-wp_genesis 1247 * @since 2.7.0
mp-wp_genesis 1248 *
mp-wp_genesis 1249 * @param string $label Optional. Label for link text.
mp-wp_genesis 1250 * @param int $max_page Optional. Max page.
mp-wp_genesis 1251 */
mp-wp_genesis 1252 function next_comments_link($label='', $max_page = 0) {
mp-wp_genesis 1253 global $wp_query;
mp-wp_genesis 1254
mp-wp_genesis 1255 if ( !is_singular() )
mp-wp_genesis 1256 return;
mp-wp_genesis 1257
mp-wp_genesis 1258 $page = get_query_var('cpage');
mp-wp_genesis 1259
mp-wp_genesis 1260 if ( !$page )
mp-wp_genesis 1261 $page = 1;
mp-wp_genesis 1262
mp-wp_genesis 1263 $nextpage = intval($page) + 1;
mp-wp_genesis 1264
mp-wp_genesis 1265 if ( empty($max_page) )
mp-wp_genesis 1266 $max_page = $wp_query->max_num_comment_pages;
mp-wp_genesis 1267
mp-wp_genesis 1268 if ( empty($max_page) )
mp-wp_genesis 1269 $max_page = get_comment_pages_count();
mp-wp_genesis 1270
mp-wp_genesis 1271 if ( $nextpage > $max_page )
mp-wp_genesis 1272 return;
mp-wp_genesis 1273
mp-wp_genesis 1274 if ( empty($label) )
mp-wp_genesis 1275 $label = __('Newer Comments &raquo;');
mp-wp_genesis 1276
mp-wp_genesis 1277 echo '<a href="' . clean_url( get_comments_pagenum_link( $nextpage, $max_page ) );
mp-wp_genesis 1278 $attr = apply_filters( 'next_comments_link_attributes', '' );
mp-wp_genesis 1279 echo "\" $attr>". preg_replace('/&([^#])(?![a-z]{1,8};)/', '&#038;$1', $label) .'</a>';
mp-wp_genesis 1280 }
mp-wp_genesis 1281
mp-wp_genesis 1282 /**
mp-wp_genesis 1283 * Display the previous comments page link.
mp-wp_genesis 1284 *
mp-wp_genesis 1285 * @since 2.7.0
mp-wp_genesis 1286 *
mp-wp_genesis 1287 * @param string $label Optional. Label for comments link text.
mp-wp_genesis 1288 */
mp-wp_genesis 1289 function previous_comments_link($label='') {
mp-wp_genesis 1290
mp-wp_genesis 1291 if ( !is_singular() )
mp-wp_genesis 1292 return;
mp-wp_genesis 1293
mp-wp_genesis 1294 $page = get_query_var('cpage');
mp-wp_genesis 1295
mp-wp_genesis 1296 if ( !$page )
mp-wp_genesis 1297 $page = 1;
mp-wp_genesis 1298
mp-wp_genesis 1299 if ( $page <= 1 )
mp-wp_genesis 1300 return;
mp-wp_genesis 1301
mp-wp_genesis 1302 $prevpage = intval($page) - 1;
mp-wp_genesis 1303
mp-wp_genesis 1304 if ( empty($label) )
mp-wp_genesis 1305 $label = __('&laquo; Older Comments');
mp-wp_genesis 1306
mp-wp_genesis 1307 echo '<a href="' . clean_url(get_comments_pagenum_link($prevpage));
mp-wp_genesis 1308 $attr = apply_filters( 'previous_comments_link_attributes', '' );
mp-wp_genesis 1309 echo "\" $attr>". preg_replace('/&([^#])(?![a-z]{1,8};)/', '&#038;$1', $label) .'</a>';
mp-wp_genesis 1310 }
mp-wp_genesis 1311
mp-wp_genesis 1312 /**
mp-wp_genesis 1313 * Create pagination links for the comments on the current post.
mp-wp_genesis 1314 *
mp-wp_genesis 1315 * @see paginate_links()
mp-wp_genesis 1316 * @since 2.7.0
mp-wp_genesis 1317 *
mp-wp_genesis 1318 * @param string|array $args Optional args. See paginate_links.
mp-wp_genesis 1319 * @return string Markup for pagination links.
mp-wp_genesis 1320 */
mp-wp_genesis 1321 function paginate_comments_links($args = array()) {
mp-wp_genesis 1322 global $wp_query, $wp_rewrite;
mp-wp_genesis 1323
mp-wp_genesis 1324 if ( !is_singular() )
mp-wp_genesis 1325 return;
mp-wp_genesis 1326
mp-wp_genesis 1327 $page = get_query_var('cpage');
mp-wp_genesis 1328 if ( !$page )
mp-wp_genesis 1329 $page = 1;
mp-wp_genesis 1330 $max_page = get_comment_pages_count();
mp-wp_genesis 1331 $defaults = array(
mp-wp_genesis 1332 'base' => add_query_arg( 'cpage', '%#%' ),
mp-wp_genesis 1333 'format' => '',
mp-wp_genesis 1334 'total' => $max_page,
mp-wp_genesis 1335 'current' => $page,
mp-wp_genesis 1336 'echo' => true,
mp-wp_genesis 1337 'add_fragment' => '#comments'
mp-wp_genesis 1338 );
mp-wp_genesis 1339 if ( $wp_rewrite->using_permalinks() )
mp-wp_genesis 1340 $defaults['base'] = user_trailingslashit(get_permalink() . 'comment-page-%#%', 'commentpaged');
mp-wp_genesis 1341
mp-wp_genesis 1342 $args = wp_parse_args( $args, $defaults );
mp-wp_genesis 1343 $page_links = paginate_links( $args );
mp-wp_genesis 1344
mp-wp_genesis 1345 if ( $args['echo'] )
mp-wp_genesis 1346 echo $page_links;
mp-wp_genesis 1347 else
mp-wp_genesis 1348 return $page_links;
mp-wp_genesis 1349 }
mp-wp_genesis 1350
mp-wp_genesis 1351 /**
mp-wp_genesis 1352 * Retrieve the site url.
mp-wp_genesis 1353 *
mp-wp_genesis 1354 * Returns the 'site_url' option with the appropriate protocol, 'https' if
mp-wp_genesis 1355 * is_ssl() and 'http' otherwise. If $scheme is 'http' or 'https', is_ssl() is
mp-wp_genesis 1356 * overridden.
mp-wp_genesis 1357 *
mp-wp_genesis 1358 * @package WordPress
mp-wp_genesis 1359 * @since 2.6.0
mp-wp_genesis 1360 *
mp-wp_genesis 1361 * @param string $path Optional. Path relative to the site url.
mp-wp_genesis 1362 * @param string $scheme Optional. Scheme to give the site url context. Currently 'http','https', 'login', 'login_post', or 'admin'.
mp-wp_genesis 1363 * @return string Site url link with optional path appended.
mp-wp_genesis 1364 */
mp-wp_genesis 1365 function site_url($path = '', $scheme = null) {
mp-wp_genesis 1366 // should the list of allowed schemes be maintained elsewhere?
mp-wp_genesis 1367 $orig_scheme = $scheme;
mp-wp_genesis 1368 if ( !in_array($scheme, array('http', 'https')) ) {
mp-wp_genesis 1369 if ( ('login_post' == $scheme) && ( force_ssl_login() || force_ssl_admin() ) )
mp-wp_genesis 1370 $scheme = 'https';
mp-wp_genesis 1371 elseif ( ('login' == $scheme) && ( force_ssl_admin() ) )
mp-wp_genesis 1372 $scheme = 'https';
mp-wp_genesis 1373 elseif ( ('admin' == $scheme) && force_ssl_admin() )
mp-wp_genesis 1374 $scheme = 'https';
mp-wp_genesis 1375 else
mp-wp_genesis 1376 $scheme = ( is_ssl() ? 'https' : 'http' );
mp-wp_genesis 1377 }
mp-wp_genesis 1378
mp-wp_genesis 1379 $url = str_replace( 'http://', "{$scheme}://", get_option('siteurl') );
mp-wp_genesis 1380
mp-wp_genesis 1381 if ( !empty($path) && is_string($path) && strpos($path, '..') === false )
mp-wp_genesis 1382 $url .= '/' . ltrim($path, '/');
mp-wp_genesis 1383
mp-wp_genesis 1384 return apply_filters('site_url', $url, $path, $orig_scheme);
mp-wp_genesis 1385 }
mp-wp_genesis 1386
mp-wp_genesis 1387 /**
mp-wp_genesis 1388 * Retrieve the url to the admin area.
mp-wp_genesis 1389 *
mp-wp_genesis 1390 * @package WordPress
mp-wp_genesis 1391 * @since 2.6.0
mp-wp_genesis 1392 *
mp-wp_genesis 1393 * @param string $path Optional path relative to the admin url
mp-wp_genesis 1394 * @return string Admin url link with optional path appended
mp-wp_genesis 1395 */
mp-wp_genesis 1396 function admin_url($path = '') {
mp-wp_genesis 1397 $url = site_url('wp-admin/', 'admin');
mp-wp_genesis 1398
mp-wp_genesis 1399 if ( !empty($path) && is_string($path) && strpos($path, '..') === false )
mp-wp_genesis 1400 $url .= ltrim($path, '/');
mp-wp_genesis 1401
mp-wp_genesis 1402 return $url;
mp-wp_genesis 1403 }
mp-wp_genesis 1404
mp-wp_genesis 1405 /**
mp-wp_genesis 1406 * Retrieve the url to the includes directory.
mp-wp_genesis 1407 *
mp-wp_genesis 1408 * @package WordPress
mp-wp_genesis 1409 * @since 2.6.0
mp-wp_genesis 1410 *
mp-wp_genesis 1411 * @param string $path Optional. Path relative to the includes url.
mp-wp_genesis 1412 * @return string Includes url link with optional path appended.
mp-wp_genesis 1413 */
mp-wp_genesis 1414 function includes_url($path = '') {
mp-wp_genesis 1415 $url = site_url() . '/' . WPINC . '/';
mp-wp_genesis 1416
mp-wp_genesis 1417 if ( !empty($path) && is_string($path) && strpos($path, '..') === false )
mp-wp_genesis 1418 $url .= ltrim($path, '/');
mp-wp_genesis 1419
mp-wp_genesis 1420 return $url;
mp-wp_genesis 1421 }
mp-wp_genesis 1422
mp-wp_genesis 1423 /**
mp-wp_genesis 1424 * Retrieve the url to the content directory.
mp-wp_genesis 1425 *
mp-wp_genesis 1426 * @package WordPress
mp-wp_genesis 1427 * @since 2.6.0
mp-wp_genesis 1428 *
mp-wp_genesis 1429 * @param string $path Optional. Path relative to the content url.
mp-wp_genesis 1430 * @return string Content url link with optional path appended.
mp-wp_genesis 1431 */
mp-wp_genesis 1432 function content_url($path = '') {
mp-wp_genesis 1433 $scheme = ( is_ssl() ? 'https' : 'http' );
mp-wp_genesis 1434 $url = WP_CONTENT_URL;
mp-wp_genesis 1435 if ( 0 === strpos($url, 'http') ) {
mp-wp_genesis 1436 if ( is_ssl() )
mp-wp_genesis 1437 $url = str_replace( 'http://', "{$scheme}://", $url );
mp-wp_genesis 1438 }
mp-wp_genesis 1439
mp-wp_genesis 1440 if ( !empty($path) && is_string($path) && strpos($path, '..') === false )
mp-wp_genesis 1441 $url .= '/' . ltrim($path, '/');
mp-wp_genesis 1442
mp-wp_genesis 1443 return $url;
mp-wp_genesis 1444 }
mp-wp_genesis 1445
mp-wp_genesis 1446 /**
mp-wp_genesis 1447 * Retrieve the url to the plugins directory.
mp-wp_genesis 1448 *
mp-wp_genesis 1449 * @package WordPress
mp-wp_genesis 1450 * @since 2.6.0
mp-wp_genesis 1451 *
mp-wp_genesis 1452 * @param string $path Optional. Path relative to the plugins url.
mp-wp_genesis 1453 * @return string Plugins url link with optional path appended.
mp-wp_genesis 1454 */
mp-wp_genesis 1455 function plugins_url($path = '') {
mp-wp_genesis 1456 $scheme = ( is_ssl() ? 'https' : 'http' );
mp-wp_genesis 1457 $url = WP_PLUGIN_URL;
mp-wp_genesis 1458 if ( 0 === strpos($url, 'http') ) {
mp-wp_genesis 1459 if ( is_ssl() )
mp-wp_genesis 1460 $url = str_replace( 'http://', "{$scheme}://", $url );
mp-wp_genesis 1461 }
mp-wp_genesis 1462
mp-wp_genesis 1463 if ( !empty($path) && is_string($path) && strpos($path, '..') === false )
mp-wp_genesis 1464 $url .= '/' . ltrim($path, '/');
mp-wp_genesis 1465
mp-wp_genesis 1466 return $url;
mp-wp_genesis 1467 }
mp-wp_genesis 1468
mp-wp_genesis 1469 ?>