3 * WordPress Link Template Functions
10 * Display the permalink for the current post.
13 * @uses apply_filters() Calls 'the_permalink' filter on the permalink string.
15 function the_permalink() {
16 echo apply_filters('the_permalink', get_permalink());
20 * Retrieve trailing slash string, if blog set for adding trailing slashes.
22 * Conditionally adds a trailing slash if the permalink structure has a trailing
23 * slash, strips the trailing slash if not. The string is passed through the
24 * 'user_trailingslashit' filter. Will remove trailing slash from string, if
25 * blog is not set to have them.
30 * @param $string String a URL with or without a trailing slash.
31 * @param $type_of_url String the type of URL being considered (e.g. single, category, etc) for use in the filter.
34 function user_trailingslashit($string, $type_of_url = '') {
36 if ( $wp_rewrite->use_trailing_slashes )
37 $string = trailingslashit($string);
39 $string = untrailingslashit($string);
41 // Note that $type_of_url can be one of following:
42 // single, single_trackback, single_feed, single_paged, feed, category, page, year, month, day, paged
43 $string = apply_filters('user_trailingslashit', $string, $type_of_url);
48 * Display permalink anchor for current post.
50 * The permalink mode title will use the post title for the 'a' element 'id'
51 * attribute. The id mode uses 'post-' with the post ID for the 'id' attribute.
55 * @param string $mode Permalink mode can be either 'title', 'id', or default, which is 'id'.
57 function permalink_anchor($mode = 'id') {
59 switch ( strtolower($mode) ) {
61 $title = sanitize_title($post->post_title) . '-' . $post->ID;
62 echo '<a id="'.$title.'"></a>';
66 echo '<a id="post-' . $post->ID . '"></a>';
72 * Retrieve full permalink for current post or post ID.
76 * @param int $id Optional. Post ID.
77 * @param bool $leavename Optional, defaults to false. Whether to keep post name or page name.
80 function get_permalink($id = 0, $leavename = false) {
88 $leavename? '' : '%postname%',
92 $leavename? '' : '%pagename%',
95 if ( is_object($id) && isset($id->filter) && 'sample' == $id->filter ) {
99 $post = &get_post($id);
103 if ( empty($post->ID) ) return false;
105 if ( $post->post_type == 'page' )
106 return get_page_link($post->ID, $leavename, $sample);
107 elseif ($post->post_type == 'attachment')
108 return get_attachment_link($post->ID);
110 $permalink = get_option('permalink_structure');
112 if ( '' != $permalink && !in_array($post->post_status, array('draft', 'pending')) ) {
113 $unixtime = strtotime($post->post_date);
116 if ( strpos($permalink, '%category%') !== false ) {
117 $cats = get_the_category($post->ID);
119 usort($cats, '_usort_terms_by_ID'); // order by ID
120 $category = $cats[0]->slug;
121 if ( $parent = $cats[0]->parent )
122 $category = get_category_parents($parent, false, '/', true) . $category;
124 // show default category in permalinks, without
125 // having to assign it explicitly
126 if ( empty($category) ) {
127 $default_category = get_category( get_option( 'default_category' ) );
128 $category = is_wp_error( $default_category ) ? '' : $default_category->slug;
133 if ( strpos($permalink, '%author%') !== false ) {
134 $authordata = get_userdata($post->post_author);
135 $author = $authordata->user_nicename;
138 $date = explode(" ",date('Y m d H i s', $unixtime));
153 $permalink = get_option('home') . str_replace($rewritecode, $rewritereplace, $permalink);
154 $permalink = user_trailingslashit($permalink, 'single');
155 return apply_filters('post_link', $permalink, $post, $leavename);
156 } else { // if they're not using the fancy permalink option
157 $permalink = trailingslashit(get_option('home')) . '?p=' . $post->ID;
158 return apply_filters('post_link', $permalink, $post, $leavename);
163 * Retrieve permalink from post ID.
167 * @param int $post_id Optional. Post ID.
168 * @param mixed $deprecated Not used.
171 function post_permalink($post_id = 0, $deprecated = '') {
172 return get_permalink($post_id);
176 * Retrieve the permalink for current page or page ID.
178 * Respects page_on_front. Use this one.
182 * @param int $id Optional. Post ID.
183 * @param bool $leavename Optional, defaults to false. Whether to keep page name.
184 * @param bool $sample Optional, defaults to false. Is it a sample permalink.
187 function get_page_link( $id = false, $leavename = false, $sample = false ) {
192 $id = (int) $post->ID;
194 if ( 'page' == get_option('show_on_front') && $id == get_option('page_on_front') )
195 $link = get_option('home');
197 $link = _get_page_link( $id , $leavename, $sample );
199 return apply_filters('page_link', $link, $id);
203 * Retrieve the page permalink.
205 * Ignores page_on_front. Internal use only.
210 * @param int $id Optional. Post ID.
211 * @param bool $leavename Optional. Leave name.
212 * @param bool $sample Optional. Sample permalink.
215 function _get_page_link( $id = false, $leavename = false, $sample = false ) {
216 global $post, $wp_rewrite;
219 $id = (int) $post->ID;
221 $post = &get_post($id);
223 $pagestruct = $wp_rewrite->get_page_permastruct();
225 if ( '' != $pagestruct && ( ( isset($post->post_status) && 'draft' != $post->post_status && 'pending' != $post->post_status ) || $sample ) ) {
226 $link = get_page_uri($id);
227 $link = ( $leavename ) ? $pagestruct : str_replace('%pagename%', $link, $pagestruct);
228 $link = trailingslashit(get_option('home')) . "$link";
229 $link = user_trailingslashit($link, 'page');
231 $link = trailingslashit(get_option('home')) . "?page_id=$id";
234 return apply_filters( '_get_page_link', $link, $id );
238 * Retrieve permalink for attachment.
240 * This can be used in the WordPress Loop or outside of it.
244 * @param int $id Optional. Post ID.
247 function get_attachment_link($id = false) {
248 global $post, $wp_rewrite;
253 $id = (int) $post->ID;
256 $object = get_post($id);
257 if ( $wp_rewrite->using_permalinks() && ($object->post_parent > 0) && ($object->post_parent != $id) ) {
258 $parent = get_post($object->post_parent);
259 if ( 'page' == $parent->post_type )
260 $parentlink = _get_page_link( $object->post_parent ); // Ignores page_on_front
262 $parentlink = get_permalink( $object->post_parent );
263 if ( is_numeric($object->post_name) || false !== strpos(get_option('permalink_structure'), '%category%') )
264 $name = 'attachment/' . $object->post_name; // <permalink>/<int>/ is paged so we use the explicit attachment marker
266 $name = $object->post_name;
267 if (strpos($parentlink, '?') === false)
268 $link = user_trailingslashit( trailingslashit($parentlink) . $name );
272 $link = trailingslashit(get_bloginfo('url')) . "?attachment_id=$id";
275 return apply_filters('attachment_link', $link, $id);
279 * Retrieve the permalink for the year archives.
283 * @param int|bool $year False for current year or year for permalink.
286 function get_year_link($year) {
289 $year = gmdate('Y', time()+(get_option('gmt_offset') * 3600));
290 $yearlink = $wp_rewrite->get_year_permastruct();
291 if ( !empty($yearlink) ) {
292 $yearlink = str_replace('%year%', $year, $yearlink);
293 return apply_filters('year_link', get_option('home') . user_trailingslashit($yearlink, 'year'), $year);
295 return apply_filters('year_link', trailingslashit(get_option('home')) . '?m=' . $year, $year);
300 * Retrieve the permalink for the month archives with year.
304 * @param bool|int $year False for current year. Integer of year.
305 * @param bool|int $month False for current month. Integer of month.
308 function get_month_link($year, $month) {
311 $year = gmdate('Y', time()+(get_option('gmt_offset') * 3600));
313 $month = gmdate('m', time()+(get_option('gmt_offset') * 3600));
314 $monthlink = $wp_rewrite->get_month_permastruct();
315 if ( !empty($monthlink) ) {
316 $monthlink = str_replace('%year%', $year, $monthlink);
317 $monthlink = str_replace('%monthnum%', zeroise(intval($month), 2), $monthlink);
318 return apply_filters('month_link', get_option('home') . user_trailingslashit($monthlink, 'month'), $year, $month);
320 return apply_filters('month_link', trailingslashit(get_option('home')) . '?m=' . $year . zeroise($month, 2), $year, $month);
325 * Retrieve the permalink for the day archives with year and month.
329 * @param bool|int $year False for current year. Integer of year.
330 * @param bool|int $month False for current month. Integer of month.
331 * @param bool|int $day False for current day. Integer of day.
334 function get_day_link($year, $month, $day) {
337 $year = gmdate('Y', time()+(get_option('gmt_offset') * 3600));
339 $month = gmdate('m', time()+(get_option('gmt_offset') * 3600));
341 $day = gmdate('j', time()+(get_option('gmt_offset') * 3600));
343 $daylink = $wp_rewrite->get_day_permastruct();
344 if ( !empty($daylink) ) {
345 $daylink = str_replace('%year%', $year, $daylink);
346 $daylink = str_replace('%monthnum%', zeroise(intval($month), 2), $daylink);
347 $daylink = str_replace('%day%', zeroise(intval($day), 2), $daylink);
348 return apply_filters('day_link', get_option('home') . user_trailingslashit($daylink, 'day'), $year, $month, $day);
350 return apply_filters('day_link', trailingslashit(get_option('home')) . '?m=' . $year . zeroise($month, 2) . zeroise($day, 2), $year, $month, $day);
355 * Retrieve the permalink for the feed type.
359 * @param string $feed Optional, defaults to default feed. Feed type.
362 function get_feed_link($feed = '') {
365 $permalink = $wp_rewrite->get_feed_permastruct();
366 if ( '' != $permalink ) {
367 if ( false !== strpos($feed, 'comments_') ) {
368 $feed = str_replace('comments_', '', $feed);
369 $permalink = $wp_rewrite->get_comment_feed_permastruct();
372 if ( get_default_feed() == $feed )
375 $permalink = str_replace('%feed%', $feed, $permalink);
376 $permalink = preg_replace('#/+#', '/', "/$permalink");
377 $output = get_option('home') . user_trailingslashit($permalink, 'feed');
380 $feed = get_default_feed();
382 if ( false !== strpos($feed, 'comments_') )
383 $feed = str_replace('comments_', 'comments-', $feed);
385 $output = trailingslashit(get_option('home')) . "?feed={$feed}";
388 return apply_filters('feed_link', $output, $feed);
392 * Retrieve the permalink for the post comments feed.
396 * @param int $post_id Optional. Post ID.
397 * @param string $feed Optional. Feed type.
400 function get_post_comments_feed_link($post_id = '', $feed = '') {
403 if ( empty($post_id) )
404 $post_id = (int) $id;
407 $feed = get_default_feed();
409 if ( '' != get_option('permalink_structure') ) {
410 $url = trailingslashit( get_permalink($post_id) ) . 'feed';
411 if ( $feed != get_default_feed() )
413 $url = user_trailingslashit($url, 'single_feed');
415 $type = get_post_field('post_type', $post_id);
416 if ( 'page' == $type )
417 $url = trailingslashit(get_option('home')) . "?feed=$feed&page_id=$post_id";
419 $url = trailingslashit(get_option('home')) . "?feed=$feed&p=$post_id";
422 return apply_filters('post_comments_feed_link', $url);
426 * Display the comment feed link for a post.
428 * Prints out the comment feed link for a post. Link text is placed in the
429 * anchor. If no link text is specified, default text is used. If no post ID is
430 * specified, the current post is used.
436 * @param string $link_text Descriptive text.
437 * @param int $post_id Optional post ID. Default to current post.
438 * @param string $feed Optional. Feed format.
439 * @return string Link to the comment feed for the current post.
441 function post_comments_feed_link( $link_text = '', $post_id = '', $feed = '' ) {
442 $url = get_post_comments_feed_link($post_id, $feed);
443 if ( empty($link_text) )
444 $link_text = __('Comments Feed');
446 echo apply_filters( 'post_comments_feed_link_html', "<a href='$url'>$link_text</a>", $post_id, $feed );
450 * Retrieve the feed link for a given author.
452 * Returns a link to the feed for all posts by a given author. A specific feed
453 * can be requested or left blank to get the default feed.
459 * @param int $author_id ID of an author.
460 * @param string $feed Optional. Feed type.
461 * @return string Link to the feed for the author specified by $author_id.
463 function get_author_feed_link( $author_id, $feed = '' ) {
464 $author_id = (int) $author_id;
465 $permalink_structure = get_option('permalink_structure');
468 $feed = get_default_feed();
470 if ( '' == $permalink_structure ) {
471 $link = trailingslashit(get_option('home')) . "?feed=$feed&author=" . $author_id;
473 $link = get_author_posts_url($author_id);
474 if ( $feed == get_default_feed() )
477 $feed_link = "feed/$feed";
479 $link = trailingslashit($link) . user_trailingslashit($feed_link, 'feed');
482 $link = apply_filters('author_feed_link', $link, $feed);
488 * Retrieve the feed link for a category.
490 * Returns a link to the feed for all post in a given category. A specific feed
491 * can be requested or left blank to get the default feed.
497 * @param int $cat_id ID of a category.
498 * @param string $feed Optional. Feed type.
499 * @return string Link to the feed for the category specified by $cat_id.
501 function get_category_feed_link($cat_id, $feed = '') {
502 $cat_id = (int) $cat_id;
504 $category = get_category($cat_id);
506 if ( empty($category) || is_wp_error($category) )
510 $feed = get_default_feed();
512 $permalink_structure = get_option('permalink_structure');
514 if ( '' == $permalink_structure ) {
515 $link = trailingslashit(get_option('home')) . "?feed=$feed&cat=" . $cat_id;
517 $link = get_category_link($cat_id);
518 if( $feed == get_default_feed() )
521 $feed_link = "feed/$feed";
523 $link = trailingslashit($link) . user_trailingslashit($feed_link, 'feed');
526 $link = apply_filters('category_feed_link', $link, $feed);
532 * Retrieve permalink for feed of tag.
536 * @param int $tag_id Tag ID.
537 * @param string $feed Optional. Feed type.
540 function get_tag_feed_link($tag_id, $feed = '') {
541 $tag_id = (int) $tag_id;
543 $tag = get_tag($tag_id);
545 if ( empty($tag) || is_wp_error($tag) )
548 $permalink_structure = get_option('permalink_structure');
551 $feed = get_default_feed();
553 if ( '' == $permalink_structure ) {
554 $link = trailingslashit(get_option('home')) . "?feed=$feed&tag=" . $tag->slug;
556 $link = get_tag_link($tag->term_id);
557 if ( $feed == get_default_feed() )
560 $feed_link = "feed/$feed";
561 $link = trailingslashit($link) . user_trailingslashit($feed_link, 'feed');
564 $link = apply_filters('tag_feed_link', $link, $feed);
570 * Retrieve edit tag link.
574 * @param int $tag_id Tag ID
577 function get_edit_tag_link( $tag_id = 0, $taxonomy = 'post_tag' ) {
578 $tag = get_term($tag_id, $taxonomy);
580 if ( !current_user_can('manage_categories') )
583 $location = admin_url('edit-tags.php?action=edit&taxonomy=' . $taxonomy . '&tag_ID=' . $tag->term_id);
584 return apply_filters( 'get_edit_tag_link', $location );
588 * Display or retrieve edit tag link with formatting.
592 * @param string $link Optional. Anchor text.
593 * @param string $before Optional. Display before edit link.
594 * @param string $after Optional. Display after edit link.
595 * @param int|object $tag Tag object or ID
596 * @return string|null HTML content, if $echo is set to false.
598 function edit_tag_link( $link = '', $before = '', $after = '', $tag = null ) {
599 $tag = get_term($tag, 'post_tag');
601 if ( !current_user_can('manage_categories') )
605 $link = __('Edit This');
607 $link = '<a href="' . get_edit_tag_link( $tag->term_id ) . '" title="' . __( 'Edit tag' ) . '">' . $link . '</a>';
608 echo $before . apply_filters( 'edit_tag_link', $link, $tag->term_id ) . $after;
612 * Retrieve the permalink for the feed of the search results.
616 * @param string $search_query Optional. Search query.
617 * @param string $feed Optional. Feed type.
620 function get_search_feed_link($search_query = '', $feed = '') {
621 if ( empty($search_query) )
622 $search = esc_attr( urlencode(get_search_query()) );
624 $search = esc_attr( urlencode(stripslashes($search_query)) );
627 $feed = get_default_feed();
629 $link = trailingslashit(get_option('home')) . "?s=$search&feed=$feed";
631 $link = apply_filters('search_feed_link', $link);
637 * Retrieve the permalink for the comments feed of the search results.
641 * @param string $search_query Optional. Search query.
642 * @param string $feed Optional. Feed type.
645 function get_search_comments_feed_link($search_query = '', $feed = '') {
646 if ( empty($search_query) )
647 $search = esc_attr( urlencode(get_search_query()) );
649 $search = esc_attr( urlencode(stripslashes($search_query)) );
652 $feed = get_default_feed();
654 $link = trailingslashit(get_option('home')) . "?s=$search&feed=comments-$feed";
656 $link = apply_filters('search_feed_link', $link);
662 * Retrieve edit posts link for post.
664 * Can be used within the WordPress loop or outside of it. Can be used with
665 * pages, posts, attachments, and revisions.
669 * @param int $id Optional. Post ID.
670 * @param string $context Optional, default to display. How to write the '&', defaults to '&'.
673 function get_edit_post_link( $id = 0, $context = 'display' ) {
674 if ( !$post = &get_post( $id ) )
677 if ( 'display' == $context )
678 $action = 'action=edit&';
680 $action = 'action=edit&';
682 switch ( $post->post_type ) :
684 if ( !current_user_can( 'edit_page', $post->ID ) )
690 if ( !current_user_can( 'edit_post', $post->ID ) )
693 $var = 'attachment_id';
696 if ( !current_user_can( 'edit_post', $post->ID ) )
703 if ( !current_user_can( 'edit_post', $post->ID ) )
704 return apply_filters( 'get_edit_post_link', '', $post->ID, $context );;
710 return apply_filters( 'get_edit_post_link', admin_url("$file.php?{$action}$var=$post->ID"), $post->ID, $context );
714 * Display edit post link for post.
718 * @param string $link Optional. Anchor text.
719 * @param string $before Optional. Display before edit link.
720 * @param string $after Optional. Display after edit link.
721 * @param int $id Optional. Post ID.
723 function edit_post_link( $link = null, $before = '', $after = '', $id = 0 ) {
724 if ( !$post = &get_post( $id ) )
727 if ( !$url = get_edit_post_link( $post->ID ) )
730 if ( null === $link )
731 $link = __('Edit This');
733 $link = '<a class="post-edit-link" href="' . $url . '" title="' . esc_attr( __( 'Edit post' ) ) . '">' . $link . '</a>';
734 echo $before . apply_filters( 'edit_post_link', $link, $post->ID ) . $after;
738 * Retrieve delete posts link for post.
740 * Can be used within the WordPress loop or outside of it. Can be used with
741 * pages, posts, attachments, and revisions.
745 * @param int $id Optional. Post ID.
746 * @param string $context Optional, default to display. How to write the '&', defaults to '&'.
749 function get_delete_post_link($id = 0, $context = 'display') {
750 if ( !$post = &get_post( $id ) )
753 if ( 'display' == $context )
754 $action = 'action=trash&';
756 $action = 'action=trash&';
758 switch ( $post->post_type ) :
760 if ( !current_user_can( 'delete_page', $post->ID ) )
766 if ( !current_user_can( 'delete_post', $post->ID ) )
769 $var = 'attachment_id';
772 if ( !current_user_can( 'delete_post', $post->ID ) )
779 if ( !current_user_can( 'edit_post', $post->ID ) )
780 return apply_filters( 'get_delete_post_link', '', $post->ID, $context );;
786 return apply_filters( 'get_delete_post_link', wp_nonce_url( admin_url("$file.php?{$action}$var=$post->ID"), "trash-{$file}_" . $post->ID ), $context );
790 * Retrieve edit comment link.
794 * @param int $comment_id Optional. Comment ID.
797 function get_edit_comment_link( $comment_id = 0 ) {
798 $comment = &get_comment( $comment_id );
799 $post = &get_post( $comment->comment_post_ID );
801 if ( $post->post_type == 'page' ) {
802 if ( !current_user_can( 'edit_page', $post->ID ) )
805 if ( !current_user_can( 'edit_post', $post->ID ) )
809 $location = admin_url('comment.php?action=editcomment&c=') . $comment->comment_ID;
810 return apply_filters( 'get_edit_comment_link', $location );
814 * Display or retrieve edit comment link with formatting.
818 * @param string $link Optional. Anchor text.
819 * @param string $before Optional. Display before edit link.
820 * @param string $after Optional. Display after edit link.
821 * @return string|null HTML content, if $echo is set to false.
823 function edit_comment_link( $link = null, $before = '', $after = '' ) {
824 global $comment, $post;
826 if ( $post->post_type == 'page' ) {
827 if ( !current_user_can( 'edit_page', $post->ID ) )
830 if ( !current_user_can( 'edit_post', $post->ID ) )
834 if ( null === $link )
835 $link = __('Edit This');
837 $link = '<a class="comment-edit-link" href="' . get_edit_comment_link( $comment->comment_ID ) . '" title="' . __( 'Edit comment' ) . '">' . $link . '</a>';
838 echo $before . apply_filters( 'edit_comment_link', $link, $comment->comment_ID ) . $after;
842 * Display edit bookmark (literally a URL external to blog) link.
846 * @param int $link Optional. Bookmark ID.
849 function get_edit_bookmark_link( $link = 0 ) {
850 $link = get_bookmark( $link );
852 if ( !current_user_can('manage_links') )
855 $location = admin_url('link.php?action=edit&link_id=') . $link->link_id;
856 return apply_filters( 'get_edit_bookmark_link', $location, $link->link_id );
860 * Display edit bookmark (literally a URL external to blog) link anchor content.
864 * @param string $link Optional. Anchor text.
865 * @param string $before Optional. Display before edit link.
866 * @param string $after Optional. Display after edit link.
867 * @param int $bookmark Optional. Bookmark ID.
869 function edit_bookmark_link( $link = '', $before = '', $after = '', $bookmark = null ) {
870 $bookmark = get_bookmark($bookmark);
872 if ( !current_user_can('manage_links') )
876 $link = __('Edit This');
878 $link = '<a href="' . get_edit_bookmark_link( $link ) . '" title="' . __( 'Edit link' ) . '">' . $link . '</a>';
879 echo $before . apply_filters( 'edit_bookmark_link', $link, $bookmark->link_id ) . $after;
885 * Retrieve previous post link that is adjacent to current post.
889 * @param bool $in_same_cat Optional. Whether link should be in same category.
890 * @param string $excluded_categories Optional. Excluded categories IDs.
893 function get_previous_post($in_same_cat = false, $excluded_categories = '') {
894 return get_adjacent_post($in_same_cat, $excluded_categories);
898 * Retrieve next post link that is adjacent to current post.
902 * @param bool $in_same_cat Optional. Whether link should be in same category.
903 * @param string $excluded_categories Optional. Excluded categories IDs.
906 function get_next_post($in_same_cat = false, $excluded_categories = '') {
907 return get_adjacent_post($in_same_cat, $excluded_categories, false);
911 * Retrieve adjacent post link.
913 * Can either be next or previous post link.
917 * @param bool $in_same_cat Optional. Whether link should be in same category.
918 * @param string $excluded_categories Optional. Excluded categories IDs.
919 * @param bool $previous Optional. Whether to retrieve previous post.
922 function get_adjacent_post($in_same_cat = false, $excluded_categories = '', $previous = true) {
925 if ( empty($post) || !is_single() || is_attachment() )
928 $current_post_date = $post->post_date;
931 $posts_in_ex_cats_sql = '';
932 if ( $in_same_cat || !empty($excluded_categories) ) {
933 $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";
935 if ( $in_same_cat ) {
936 $cat_array = wp_get_object_terms($post->ID, 'category', 'fields=ids');
937 $join .= " AND tt.taxonomy = 'category' AND tt.term_id IN (" . implode(',', $cat_array) . ")";
940 $posts_in_ex_cats_sql = "AND tt.taxonomy = 'category'";
941 if ( !empty($excluded_categories) ) {
942 $excluded_categories = array_map('intval', explode(' and ', $excluded_categories));
943 if ( !empty($cat_array) ) {
944 $excluded_categories = array_diff($excluded_categories, $cat_array);
945 $posts_in_ex_cats_sql = '';
948 if ( !empty($excluded_categories) ) {
949 $posts_in_ex_cats_sql = " AND tt.taxonomy = 'category' AND tt.term_id NOT IN (" . implode($excluded_categories, ',') . ')';
954 $adjacent = $previous ? 'previous' : 'next';
955 $op = $previous ? '<' : '>';
956 $order = $previous ? 'DESC' : 'ASC';
958 $join = apply_filters( "get_{$adjacent}_post_join", $join, $in_same_cat, $excluded_categories );
959 $where = apply_filters( "get_{$adjacent}_post_where", $wpdb->prepare("WHERE p.post_date $op %s AND p.post_type = %s AND p.post_status = 'publish' $posts_in_ex_cats_sql", $current_post_date, $post->post_type), $in_same_cat, $excluded_categories );
960 $sort = apply_filters( "get_{$adjacent}_post_sort", "ORDER BY p.post_date $order LIMIT 1" );
962 $query = "SELECT p.* FROM $wpdb->posts AS p $join $where $sort";
963 $query_key = 'adjacent_post_' . md5($query);
964 $result = wp_cache_get($query_key, 'counts');
965 if ( false !== $result )
968 $result = $wpdb->get_row("SELECT p.* FROM $wpdb->posts AS p $join $where $sort");
969 if ( null === $result )
972 wp_cache_set($query_key, $result, 'counts');
977 * Get adjacent post relational link.
979 * Can either be next or previous post relational link.
983 * @param string $title Optional. Link title format.
984 * @param bool $in_same_cat Optional. Whether link should be in same category.
985 * @param string $excluded_categories Optional. Excluded categories IDs.
986 * @param bool $previous Optional, default is true. Whether display link to previous post.
989 function get_adjacent_post_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '', $previous = true) {
990 if ( $previous && is_attachment() )
991 $post = & get_post($GLOBALS['post']->post_parent);
993 $post = get_adjacent_post($in_same_cat,$excluded_categories,$previous);
998 if ( empty($post->post_title) )
999 $post->post_title = $previous ? __('Previous Post') : __('Next Post');
1001 $date = mysql2date(get_option('date_format'), $post->post_date);
1003 $title = str_replace('%title', $post->post_title, $title);
1004 $title = str_replace('%date', $date, $title);
1005 $title = apply_filters('the_title', $title, $post);
1007 $link = $previous ? "<link rel='prev' title='" : "<link rel='next' title='";
1008 $link .= esc_attr( $title );
1009 $link .= "' href='" . get_permalink($post) . "' />\n";
1011 $adjacent = $previous ? 'previous' : 'next';
1012 return apply_filters( "{$adjacent}_post_rel_link", $link );
1016 * Display relational links for the posts adjacent to the current post.
1020 * @param string $title Optional. Link title format.
1021 * @param bool $in_same_cat Optional. Whether link should be in same category.
1022 * @param string $excluded_categories Optional. Excluded categories IDs.
1024 function adjacent_posts_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '') {
1025 echo get_adjacent_post_rel_link($title, $in_same_cat, $excluded_categories = '', true);
1026 echo get_adjacent_post_rel_link($title, $in_same_cat, $excluded_categories = '', false);
1030 * Display relational link for the next post adjacent to the current post.
1034 * @param string $title Optional. Link title format.
1035 * @param bool $in_same_cat Optional. Whether link should be in same category.
1036 * @param string $excluded_categories Optional. Excluded categories IDs.
1038 function next_post_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '') {
1039 echo get_adjacent_post_rel_link($title, $in_same_cat, $excluded_categories = '', false);
1043 * Display relational link for the previous post adjacent to the current post.
1047 * @param string $title Optional. Link title format.
1048 * @param bool $in_same_cat Optional. Whether link should be in same category.
1049 * @param string $excluded_categories Optional. Excluded categories IDs.
1051 function prev_post_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '') {
1052 echo get_adjacent_post_rel_link($title, $in_same_cat, $excluded_categories = '', true);
1056 * Retrieve boundary post.
1058 * Boundary being either the first or last post by publish date within the contraitns specified
1059 * by in same category or excluded categories.
1063 * @param bool $in_same_cat Optional. Whether returned post should be in same category.
1064 * @param string $excluded_categories Optional. Excluded categories IDs.
1065 * @param bool $previous Optional. Whether to retrieve first post.
1068 function get_boundary_post($in_same_cat = false, $excluded_categories = '', $start = true) {
1069 global $post, $wpdb;
1071 if ( empty($post) || !is_single() || is_attachment() )
1074 $cat_array = array();
1075 $excluded_categories = array();
1076 if ( !empty($in_same_cat) || !empty($excluded_categories) ) {
1077 if ( !empty($in_same_cat) ) {
1078 $cat_array = wp_get_object_terms($post->ID, 'category', 'fields=ids');
1081 if ( !empty($excluded_categories) ) {
1082 $excluded_categories = array_map('intval', explode(',', $excluded_categories));
1084 if ( !empty($cat_array) )
1085 $excluded_categories = array_diff($excluded_categories, $cat_array);
1087 $inverse_cats = array();
1088 foreach ( $excluded_categories as $excluded_category)
1089 $inverse_cats[] = $excluded_category * -1;
1090 $excluded_categories = $inverse_cats;
1094 $categories = implode(',', array_merge($cat_array, $excluded_categories) );
1096 $order = $start ? 'ASC' : 'DESC';
1098 return get_posts( array('numberposts' => 1, 'order' => $order, 'orderby' => 'ID', 'category' => $categories) );
1102 * Get boundary post relational link.
1104 * Can either be start or end post relational link.
1108 * @param string $title Optional. Link title format.
1109 * @param bool $in_same_cat Optional. Whether link should be in same category.
1110 * @param string $excluded_categories Optional. Excluded categories IDs.
1111 * @param bool $start Optional, default is true. Whether display link to first post.
1114 function get_boundary_post_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '', $start = true) {
1115 $posts = get_boundary_post($in_same_cat,$excluded_categories,$start);
1116 // Even though we limited get_posts to return only 1 item it still returns an array of objects.
1122 if ( empty($post->post_title) )
1123 $post->post_title = $start ? __('First Post') : __('Last Post');
1125 $date = mysql2date(get_option('date_format'), $post->post_date);
1127 $title = str_replace('%title', $post->post_title, $title);
1128 $title = str_replace('%date', $date, $title);
1129 $title = apply_filters('the_title', $title, $post);
1131 $link = $start ? "<link rel='start' title='" : "<link rel='end' title='";
1132 $link .= esc_attr($title);
1133 $link .= "' href='" . get_permalink($post) . "' />\n";
1135 $boundary = $start ? 'start' : 'end';
1136 return apply_filters( "{$boundary}_post_rel_link", $link );
1140 * Display relational link for the first post.
1144 * @param string $title Optional. Link title format.
1145 * @param bool $in_same_cat Optional. Whether link should be in same category.
1146 * @param string $excluded_categories Optional. Excluded categories IDs.
1148 function start_post_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '') {
1149 echo get_boundary_post_rel_link($title, $in_same_cat, $excluded_categories, true);
1153 * Get site index relational link.
1159 function get_index_rel_link() {
1160 $link = "<link rel='index' title='" . esc_attr(get_bloginfo('name')) . "' href='" . get_bloginfo('siteurl') . "' />\n";
1161 return apply_filters( "index_rel_link", $link );
1165 * Display relational link for the site index.
1169 function index_rel_link() {
1170 echo get_index_rel_link();
1174 * Get parent post relational link.
1178 * @param string $title Optional. Link title format.
1181 function get_parent_post_rel_link($title = '%title') {
1182 if ( ! empty( $GLOBALS['post'] ) && ! empty( $GLOBALS['post']->post_parent ) )
1183 $post = & get_post($GLOBALS['post']->post_parent);
1188 $date = mysql2date(get_option('date_format'), $post->post_date);
1190 $title = str_replace('%title', $post->post_title, $title);
1191 $title = str_replace('%date', $date, $title);
1192 $title = apply_filters('the_title', $title, $post);
1194 $link = "<link rel='up' title='";
1195 $link .= esc_attr( $title );
1196 $link .= "' href='" . get_permalink($post) . "' />\n";
1198 return apply_filters( "parent_post_rel_link", $link );
1202 * Display relational link for parent item
1206 function parent_post_rel_link($title = '%title') {
1207 echo get_parent_post_rel_link($title);
1211 * Display previous post link that is adjacent to the current post.
1215 * @param string $format Optional. Link anchor format.
1216 * @param string $link Optional. Link permalink format.
1217 * @param bool $in_same_cat Optional. Whether link should be in same category.
1218 * @param string $excluded_categories Optional. Excluded categories IDs.
1220 function previous_post_link($format='« %link', $link='%title', $in_same_cat = false, $excluded_categories = '') {
1221 adjacent_post_link($format, $link, $in_same_cat, $excluded_categories, true);
1225 * Display next post link that is adjacent to the current post.
1229 * @param string $format Optional. Link anchor format.
1230 * @param string $link Optional. Link permalink format.
1231 * @param bool $in_same_cat Optional. Whether link should be in same category.
1232 * @param string $excluded_categories Optional. Excluded categories IDs.
1234 function next_post_link($format='%link »', $link='%title', $in_same_cat = false, $excluded_categories = '') {
1235 adjacent_post_link($format, $link, $in_same_cat, $excluded_categories, false);
1239 * Display adjacent post link.
1241 * Can be either next post link or previous.
1245 * @param string $format Link anchor format.
1246 * @param string $link Link permalink format.
1247 * @param bool $in_same_cat Optional. Whether link should be in same category.
1248 * @param string $excluded_categories Optional. Excluded categories IDs.
1249 * @param bool $previous Optional, default is true. Whether display link to previous post.
1251 function adjacent_post_link($format, $link, $in_same_cat = false, $excluded_categories = '', $previous = true) {
1252 if ( $previous && is_attachment() )
1253 $post = & get_post($GLOBALS['post']->post_parent);
1255 $post = get_adjacent_post($in_same_cat, $excluded_categories, $previous);
1260 $title = $post->post_title;
1262 if ( empty($post->post_title) )
1263 $title = $previous ? __('Previous Post') : __('Next Post');
1265 $title = apply_filters('the_title', $title, $post);
1266 $date = mysql2date(get_option('date_format'), $post->post_date);
1267 $rel = $previous ? 'prev' : 'next';
1269 $string = '<a href="'.get_permalink($post).'" rel="'.$rel.'">';
1270 $link = str_replace('%title', $title, $link);
1271 $link = str_replace('%date', $date, $link);
1272 $link = $string . $link . '</a>';
1274 $format = str_replace('%link', $link, $format);
1276 $adjacent = $previous ? 'previous' : 'next';
1277 echo apply_filters( "{$adjacent}_post_link", $format, $link );
1281 * Retrieve get links for page numbers.
1285 * @param int $pagenum Optional. Page ID.
1288 function get_pagenum_link($pagenum = 1) {
1291 $pagenum = (int) $pagenum;
1293 $request = remove_query_arg( 'paged' );
1295 $home_root = parse_url(get_option('home'));
1296 $home_root = ( isset($home_root['path']) ) ? $home_root['path'] : '';
1297 $home_root = preg_quote( trailingslashit( $home_root ), '|' );
1299 $request = preg_replace('|^'. $home_root . '|', '', $request);
1300 $request = preg_replace('|^/+|', '', $request);
1302 if ( !$wp_rewrite->using_permalinks() || is_admin() ) {
1303 $base = trailingslashit( get_bloginfo( 'home' ) );
1305 if ( $pagenum > 1 ) {
1306 $result = add_query_arg( 'paged', $pagenum, $base . $request );
1308 $result = $base . $request;
1311 $qs_regex = '|\?.*?$|';
1312 preg_match( $qs_regex, $request, $qs_match );
1314 if ( !empty( $qs_match[0] ) ) {
1315 $query_string = $qs_match[0];
1316 $request = preg_replace( $qs_regex, '', $request );
1321 $request = preg_replace( '|page/\d+/?$|', '', $request);
1322 $request = preg_replace( '|^index\.php|', '', $request);
1323 $request = ltrim($request, '/');
1325 $base = trailingslashit( get_bloginfo( 'url' ) );
1327 if ( $wp_rewrite->using_index_permalinks() && ( $pagenum > 1 || '' != $request ) )
1328 $base .= 'index.php/';
1330 if ( $pagenum > 1 ) {
1331 $request = ( ( !empty( $request ) ) ? trailingslashit( $request ) : $request ) . user_trailingslashit( 'page/' . $pagenum, 'paged' );
1334 $result = $base . $request . $query_string;
1337 $result = apply_filters('get_pagenum_link', $result);
1343 * Retrieve next posts pages link.
1345 * Backported from 2.1.3 to 2.0.10.
1349 * @param int $max_page Optional. Max pages.
1352 function get_next_posts_page_link($max_page = 0) {
1355 if ( !is_single() ) {
1358 $nextpage = intval($paged) + 1;
1359 if ( !$max_page || $max_page >= $nextpage )
1360 return get_pagenum_link($nextpage);
1365 * Display or return the next posts pages link.
1369 * @param int $max_page Optional. Max pages.
1370 * @param boolean $echo Optional. Echo or return;
1372 function next_posts( $max_page = 0, $echo = true ) {
1373 $output = esc_url( get_next_posts_page_link( $max_page ) );
1382 * Return the next posts pages link.
1386 * @param string $label Content for link text.
1387 * @param int $max_page Optional. Max pages.
1388 * @return string|null
1390 function get_next_posts_link( $label = 'Next Page »', $max_page = 0 ) {
1391 global $paged, $wp_query;
1394 $max_page = $wp_query->max_num_pages;
1400 $nextpage = intval($paged) + 1;
1402 if ( !is_single() && ( empty($paged) || $nextpage <= $max_page) ) {
1403 $attr = apply_filters( 'next_posts_link_attributes', '' );
1404 return '<a href="' . next_posts( $max_page, false ) . "\" $attr>". preg_replace('/&([^#])(?![a-z]{1,8};)/', '&$1', $label) .'</a>';
1409 * Display the next posts pages link.
1412 * @uses get_next_posts_link()
1414 * @param string $label Content for link text.
1415 * @param int $max_page Optional. Max pages.
1417 function next_posts_link( $label = 'Next Page »', $max_page = 0 ) {
1418 echo get_next_posts_link( $label, $max_page );
1422 * Retrieve previous post pages link.
1424 * Will only return string, if not on a single page or post.
1426 * Backported to 2.0.10 from 2.1.3.
1430 * @return string|null
1432 function get_previous_posts_page_link() {
1435 if ( !is_single() ) {
1436 $nextpage = intval($paged) - 1;
1437 if ( $nextpage < 1 )
1439 return get_pagenum_link($nextpage);
1444 * Display or return the previous posts pages link.
1448 * @param boolean $echo Optional. Echo or return;
1450 function previous_posts( $echo = true ) {
1451 $output = esc_url( get_previous_posts_page_link() );
1460 * Return the previous posts pages link.
1464 * @param string $label Optional. Previous page link text.
1465 * @return string|null
1467 function get_previous_posts_link( $label = '« Previous Page' ) {
1470 if ( !is_single() && $paged > 1 ) {
1471 $attr = apply_filters( 'previous_posts_link_attributes', '' );
1472 return '<a href="' . previous_posts( false ) . "\" $attr>". preg_replace( '/&([^#])(?![a-z]{1,8};)/', '&$1', $label ) .'</a>';
1477 * Display the previous posts page link.
1480 * @uses get_previous_posts_link()
1482 * @param string $label Optional. Previous page link text.
1484 function previous_posts_link( $label = '« Previous Page' ) {
1485 echo get_previous_posts_link( $label );
1489 * Return post pages link navigation for previous and next pages.
1493 * @param string|array $args Optional args.
1494 * @return string The posts link navigation.
1496 function get_posts_nav_link( $args = array() ) {
1501 if ( !is_singular() ) {
1503 'sep' => ' — ',
1504 'prelabel' => __('« Previous Page'),
1505 'nxtlabel' => __('Next Page »'),
1507 $args = wp_parse_args( $args, $defaults );
1509 $max_num_pages = $wp_query->max_num_pages;
1510 $paged = get_query_var('paged');
1512 //only have sep if there's both prev and next results
1513 if ($paged < 2 || $paged >= $max_num_pages) {
1517 if ( $max_num_pages > 1 ) {
1518 $return = get_previous_posts_link($args['prelabel']);
1519 $return .= preg_replace('/&([^#])(?![a-z]{1,8};)/', '&$1', $args['sep']);
1520 $return .= get_next_posts_link($args['nxtlabel']);
1528 * Display post pages link navigation for previous and next pages.
1532 * @param string $sep Optional. Separator for posts navigation links.
1533 * @param string $prelabel Optional. Label for previous pages.
1534 * @param string $nxtlabel Optional Label for next pages.
1536 function posts_nav_link( $sep = '', $prelabel = '', $nxtlabel = '' ) {
1537 $args = array_filter( compact('sep', 'prelabel', 'nxtlabel') );
1538 echo get_posts_nav_link($args);
1542 * Retrieve page numbers links.
1546 * @param int $pagenum Optional. Page number.
1549 function get_comments_pagenum_link( $pagenum = 1, $max_page = 0 ) {
1550 global $post, $wp_rewrite;
1552 $pagenum = (int) $pagenum;
1554 $result = get_permalink( $post->ID );
1556 if ( 'newest' == get_option('default_comments_page') ) {
1557 if ( $pagenum != $max_page ) {
1558 if ( $wp_rewrite->using_permalinks() )
1559 $result = user_trailingslashit( trailingslashit($result) . 'comment-page-' . $pagenum, 'commentpaged');
1561 $result = add_query_arg( 'cpage', $pagenum, $result );
1563 } elseif ( $pagenum > 1 ) {
1564 if ( $wp_rewrite->using_permalinks() )
1565 $result = user_trailingslashit( trailingslashit($result) . 'comment-page-' . $pagenum, 'commentpaged');
1567 $result = add_query_arg( 'cpage', $pagenum, $result );
1570 $result .= '#comments';
1572 $result = apply_filters('get_comments_pagenum_link', $result);
1578 * Return the link to next comments pages.
1582 * @param string $label Optional. Label for link text.
1583 * @param int $max_page Optional. Max page.
1584 * @return string|null
1586 function get_next_comments_link( $label = '', $max_page = 0 ) {
1589 if ( !is_singular() || !get_option('page_comments') )
1592 $page = get_query_var('cpage');
1594 $nextpage = intval($page) + 1;
1596 if ( empty($max_page) )
1597 $max_page = $wp_query->max_num_comment_pages;
1599 if ( empty($max_page) )
1600 $max_page = get_comment_pages_count();
1602 if ( $nextpage > $max_page )
1605 if ( empty($label) )
1606 $label = __('Newer Comments »');
1608 return '<a href="' . esc_url( get_comments_pagenum_link( $nextpage, $max_page ) ) . '" ' . apply_filters( 'next_comments_link_attributes', '' ) . '>'. preg_replace('/&([^#])(?![a-z]{1,8};)/', '&$1', $label) .'</a>';
1612 * Display the link to next comments pages.
1616 * @param string $label Optional. Label for link text.
1617 * @param int $max_page Optional. Max page.
1619 function next_comments_link( $label = '', $max_page = 0 ) {
1620 echo get_next_comments_link( $label, $max_page );
1624 * Return the previous comments page link.
1628 * @param string $label Optional. Label for comments link text.
1629 * @return string|null
1631 function get_previous_comments_link( $label = '' ) {
1632 if ( !is_singular() || !get_option('page_comments') )
1635 $page = get_query_var('cpage');
1637 if ( intval($page) <= 1 )
1640 $prevpage = intval($page) - 1;
1642 if ( empty($label) )
1643 $label = __('« Older Comments');
1645 return '<a href="' . esc_url( get_comments_pagenum_link( $prevpage ) ) . '" ' . apply_filters( 'previous_comments_link_attributes', '' ) . '>' . preg_replace('/&([^#])(?![a-z]{1,8};)/', '&$1', $label) .'</a>';
1649 * Display the previous comments page link.
1653 * @param string $label Optional. Label for comments link text.
1655 function previous_comments_link( $label = '' ) {
1656 echo get_previous_comments_link( $label );
1660 * Create pagination links for the comments on the current post.
1662 * @see paginate_links()
1665 * @param string|array $args Optional args. See paginate_links.
1666 * @return string Markup for pagination links.
1668 function paginate_comments_links($args = array()) {
1669 global $wp_query, $wp_rewrite;
1671 if ( !is_singular() || !get_option('page_comments') )
1674 $page = get_query_var('cpage');
1677 $max_page = get_comment_pages_count();
1679 'base' => add_query_arg( 'cpage', '%#%' ),
1681 'total' => $max_page,
1684 'add_fragment' => '#comments'
1686 if ( $wp_rewrite->using_permalinks() )
1687 $defaults['base'] = user_trailingslashit(trailingslashit(get_permalink()) . 'comment-page-%#%', 'commentpaged');
1689 $args = wp_parse_args( $args, $defaults );
1690 $page_links = paginate_links( $args );
1692 if ( $args['echo'] )
1699 * Retrieve shortcut link.
1701 * Use this in 'a' element 'href' attribute.
1707 function get_shortcut_link() {
1708 $link = "javascript:
1714 s=(e?e():(k)?k():(x?x.createRange().text:0)),
1715 f='" . admin_url('press-this.php') . "',
1717 e=encodeURIComponent,
1718 u=f+'?u='+e(l.href)+'&t='+e(d.title)+'&s='+e(s)+'&v=4';
1719 a=function(){if(!w.open(u,'t','toolbar=0,resizable=1,scrollbars=1,status=1,width=720,height=570'))l.href=u;};
1720 if (/Firefox/.test(navigator.userAgent)) setTimeout(a, 0); else a();
1723 $link = str_replace(array("\r", "\n", "\t"), '', $link);
1725 return apply_filters('shortcut_link', $link);
1729 * Retrieve the site url.
1731 * Returns the 'site_url' option with the appropriate protocol, 'https' if
1732 * is_ssl() and 'http' otherwise. If $scheme is 'http' or 'https', is_ssl() is
1735 * @package WordPress
1738 * @param string $path Optional. Path relative to the site url.
1739 * @param string $scheme Optional. Scheme to give the site url context. Currently 'http','https', 'login', 'login_post', or 'admin'.
1740 * @return string Site url link with optional path appended.
1742 function site_url($path = '', $scheme = null) {
1743 // should the list of allowed schemes be maintained elsewhere?
1744 $orig_scheme = $scheme;
1745 if ( !in_array($scheme, array('http', 'https')) ) {
1746 if ( ( 'login_post' == $scheme || 'rpc' == $scheme ) && ( force_ssl_login() || force_ssl_admin() ) )
1748 elseif ( ('login' == $scheme) && ( force_ssl_admin() ) )
1750 elseif ( ('admin' == $scheme) && force_ssl_admin() )
1753 $scheme = ( is_ssl() ? 'https' : 'http' );
1756 $url = str_replace( 'http://', "{$scheme}://", get_option('siteurl') );
1758 if ( !empty($path) && is_string($path) && strpos($path, '..') === false )
1759 $url .= '/' . ltrim($path, '/');
1761 return apply_filters('site_url', $url, $path, $orig_scheme);
1765 * Retrieve the url to the admin area.
1767 * @package WordPress
1770 * @param string $path Optional path relative to the admin url
1771 * @return string Admin url link with optional path appended
1773 function admin_url($path = '') {
1774 $url = site_url('wp-admin/', 'admin');
1776 if ( !empty($path) && is_string($path) && strpos($path, '..') === false )
1777 $url .= ltrim($path, '/');
1779 return apply_filters('admin_url', $url, $path);
1783 * Retrieve the url to the includes directory.
1785 * @package WordPress
1788 * @param string $path Optional. Path relative to the includes url.
1789 * @return string Includes url link with optional path appended.
1791 function includes_url($path = '') {
1792 $url = site_url() . '/' . WPINC . '/';
1794 if ( !empty($path) && is_string($path) && strpos($path, '..') === false )
1795 $url .= ltrim($path, '/');
1797 return apply_filters('includes_url', $url, $path);
1801 * Retrieve the url to the content directory.
1803 * @package WordPress
1806 * @param string $path Optional. Path relative to the content url.
1807 * @return string Content url link with optional path appended.
1809 function content_url($path = '') {
1810 $scheme = ( is_ssl() ? 'https' : 'http' );
1811 $url = WP_CONTENT_URL;
1812 if ( 0 === strpos($url, 'http') ) {
1814 $url = str_replace( 'http://', "{$scheme}://", $url );
1817 if ( !empty($path) && is_string($path) && strpos($path, '..') === false )
1818 $url .= '/' . ltrim($path, '/');
1820 return apply_filters('content_url', $url, $path);
1824 * Retrieve the url to the plugins directory or to a specific file within that directory.
1825 * You can hardcode the plugin slug in $path or pass __FILE__ as a second argument to get the correct folder name.
1827 * @package WordPress
1830 * @param string $path Optional. Path relative to the plugins url.
1831 * @param string $plugin Optional. The plugin file that you want to be relative to - i.e. pass in __FILE__
1832 * @return string Plugins url link with optional path appended.
1834 function plugins_url($path = '', $plugin = '') {
1835 $scheme = ( is_ssl() ? 'https' : 'http' );
1837 if ( $plugin !== '' && preg_match('#^' . preg_quote(WPMU_PLUGIN_DIR . DIRECTORY_SEPARATOR, '#') . '#', $plugin) ) {
1838 $url = WPMU_PLUGIN_URL;
1840 $url = WP_PLUGIN_URL;
1843 if ( 0 === strpos($url, 'http') ) {
1845 $url = str_replace( 'http://', "{$scheme}://", $url );
1848 if ( !empty($plugin) && is_string($plugin) ) {
1849 $folder = dirname(plugin_basename($plugin));
1851 $url .= '/' . ltrim($folder, '/');
1854 if ( !empty($path) && is_string($path) && strpos($path, '..') === false )
1855 $url .= '/' . ltrim($path, '/');
1857 return apply_filters('plugins_url', $url, $path, $plugin);
1861 * Output rel=canonical for singular queries
1863 * @package WordPress
1866 function rel_canonical() {
1867 if ( !is_singular() )
1870 global $wp_the_query;
1871 if ( !$id = $wp_the_query->get_queried_object_id() )
1874 $link = get_permalink( $id );
1875 echo "<link rel='canonical' href='$link' />\n";