WordPressを読む 36-5 /blog/wp-includes/link-template.php 5
2014/12/18
目次
- 1 /blog/wp-includes/link-template.php 5
- 2 関数 adjacent_post_link()
- 3 関数 get_pagenum_link()
- 4 関数 get_next_posts_page_link()
- 5 関数 next_posts()
- 6 関数 get_next_posts_link()
- 7 関数 next_posts_link()
- 8 関数 get_previous_posts_page_link()
- 9 関数 previous_posts()
- 10 関数 get_previous_posts_link()
- 11 関数 previous_posts_link()
- 12 関数 get_posts_nav_link()
- 13 関数 posts_nav_link()
- 14 関数 get_comments_pagenum_link()
- 15 関数 get_next_comments_link()
- 16 関数 next_comments_link()
- 17 関数 get_previous_comments_link()
- 18 関数 previous_comments_link()
- 19 関数 paginate_comments_links()
/blog/wp-includes/link-template.php 5
関数 adjacent_post_link()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | /** * Display adjacent post link. * * Can be either next post link or previous. * * @since 2.5.0 * @uses get_adjacent_post_link() * * @param string $format Link anchor format. * @param string $link Link permalink format. * @param bool $in_same_term Optional. Whether link should be in a same taxonomy term. * @param array|string $excluded_terms Optional. Array or comma-separated list of excluded category IDs. * @param bool $previous Optional. Whether to display link to previous or next post. Default true. * @param string $taxonomy Optional. Taxonomy, if $in_same_term is true. Default 'category'. * @return string */ function adjacent_post_link( $format, $link, $in_same_term = false, $excluded_terms = '', $previous = true, $taxonomy = 'category' ) { echo get_adjacent_post_link( $format, $link, $in_same_term, $excluded_terms, $previous, $taxonomy ); } |
関数 get_pagenum_link()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | /** * Retrieve links for page numbers. * * @since 1.5.0 * * @param int $pagenum Optional. Page ID. * @param bool $escape Optional. Whether to escape the URL for display, with esc_url(). Defaults to true. * Otherwise, prepares the URL with esc_url_raw(). * @return string */ function get_pagenum_link($pagenum = 1, $escape = true ) { global $wp_rewrite; $pagenum = (int) $pagenum; $request = remove_query_arg( 'paged' ); $home_root = parse_url(home_url()); $home_root = ( isset($home_root['path']) ) ? $home_root['path'] : ''; $home_root = preg_quote( $home_root, '|' ); $request = preg_replace('|^'. $home_root . '|i', '', $request); $request = preg_replace('|^/+|', '', $request); if ( !$wp_rewrite->using_permalinks() || is_admin() ) { $base = trailingslashit( get_bloginfo( 'url' ) ); if ( $pagenum > 1 ) { $result = add_query_arg( 'paged', $pagenum, $base . $request ); } else { $result = $base . $request; } } else { $qs_regex = '|\?.*?$|'; preg_match( $qs_regex, $request, $qs_match ); if ( !empty( $qs_match[0] ) ) { $query_string = $qs_match[0]; $request = preg_replace( $qs_regex, '', $request ); } else { $query_string = ''; } $request = preg_replace( "|$wp_rewrite->pagination_base/\d+/?$|", '', $request); $request = preg_replace( '|^' . preg_quote( $wp_rewrite->index, '|' ) . '|i', '', $request); $request = ltrim($request, '/'); $base = trailingslashit( get_bloginfo( 'url' ) ); if ( $wp_rewrite->using_index_permalinks() && ( $pagenum > 1 || '' != $request ) ) $base .= $wp_rewrite->index . '/'; if ( $pagenum > 1 ) { $request = ( ( !empty( $request ) ) ? trailingslashit( $request ) : $request ) . user_trailingslashit( $wp_rewrite->pagination_base . "/" . $pagenum, 'paged' ); } $result = $base . $request . $query_string; } /** * Filter the page number link for the current request. * * @since 2.5.0 * * @param string $result The page number link. */ $result = apply_filters( 'get_pagenum_link', $result ); if ( $escape ) return esc_url( $result ); else return esc_url_raw( $result ); } |
関数 get_next_posts_page_link()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | /** * Retrieve next posts page link. * * Backported from 2.1.3 to 2.0.10. * * @since 2.0.10 * * @param int $max_page Optional. Max pages. * @return string */ function get_next_posts_page_link($max_page = 0) { global $paged; if ( !is_single() ) { if ( !$paged ) $paged = 1; $nextpage = intval($paged) + 1; if ( !$max_page || $max_page >= $nextpage ) return get_pagenum_link($nextpage); } } |
関数 next_posts()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | /** * Display or return the next posts page link. * * @since 0.71 * * @param int $max_page Optional. Max pages. * @param boolean $echo Optional. Echo or return; */ function next_posts( $max_page = 0, $echo = true ) { $output = esc_url( get_next_posts_page_link( $max_page ) ); if ( $echo ) echo $output; else return $output; } |
関数 get_next_posts_link()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | /** * Return the next posts page link. * * @since 2.7.0 * * @param string $label Content for link text. * @param int $max_page Optional. Max pages. * @return string|null */ function get_next_posts_link( $label = null, $max_page = 0 ) { global $paged, $wp_query; if ( !$max_page ) $max_page = $wp_query->max_num_pages; if ( !$paged ) $paged = 1; $nextpage = intval($paged) + 1; if ( null === $label ) $label = __( 'Next Page »' ); if ( !is_single() && ( $nextpage <= $max_page ) ) { /** * Filter the anchor tag attributes for the next posts page link. * * @since 2.7.0 * * @param string $attributes Attributes for the anchor tag. */ $attr = apply_filters( 'next_posts_link_attributes', '' ); return '<a href="' . next_posts( $max_page, false ) . "\" $attr>" . preg_replace('/&([^#])(?![a-z]{1,8};)/i', '&$1', $label) . '</a>'; } } |
関数 next_posts_link()
1 2 3 4 5 6 7 8 9 10 11 12 | /** * Display the next posts page link. * * @since 0.71 * @uses get_next_posts_link() * * @param string $label Content for link text. * @param int $max_page Optional. Max pages. */ function next_posts_link( $label = null, $max_page = 0 ) { echo get_next_posts_link( $label, $max_page ); } |
関数 get_previous_posts_page_link()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | /** * Retrieve previous posts page link. * * Will only return string, if not on a single page or post. * * Backported to 2.0.10 from 2.1.3. * * @since 2.0.10 * * @return string|null */ function get_previous_posts_page_link() { global $paged; if ( !is_single() ) { $nextpage = intval($paged) - 1; if ( $nextpage < 1 ) $nextpage = 1; return get_pagenum_link($nextpage); } } |
関数 previous_posts()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | /** * Display or return the previous posts page link. * * @since 0.71 * * @param boolean $echo Optional. Echo or return; */ function previous_posts( $echo = true ) { $output = esc_url( get_previous_posts_page_link() ); if ( $echo ) echo $output; else return $output; } |
関数 get_previous_posts_link()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | /** * Return the previous posts page link. * * @since 2.7.0 * * @param string $label Optional. Previous page link text. * @return string|null */ function get_previous_posts_link( $label = null ) { global $paged; if ( null === $label ) $label = __( '« Previous Page' ); if ( !is_single() && $paged > 1 ) { /** * Filter the anchor tag attributes for the previous posts page link. * * @since 2.7.0 * * @param string $attributes Attributes for the anchor tag. */ $attr = apply_filters( 'previous_posts_link_attributes', '' ); return '<a href="' . previous_posts( false ) . "\" $attr>". preg_replace( '/&([^#])(?![a-z]{1,8};)/i', '&$1', $label ) .'</a>'; } } |
関数 previous_posts_link()
1 2 3 4 5 6 7 8 9 10 11 | /** * Display the previous posts page link. * * @since 0.71 * @uses get_previous_posts_link() * * @param string $label Optional. Previous page link text. */ function previous_posts_link( $label = null ) { echo get_previous_posts_link( $label ); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | /** * Return post pages link navigation for previous and next pages. * * @since 2.8.0 * * @param string|array $args Optional args. * @return string The posts link navigation. */ function get_posts_nav_link( $args = array() ) { global $wp_query; $return = ''; if ( !is_singular() ) { $defaults = array( 'sep' => ' — ', 'prelabel' => __('« Previous Page'), 'nxtlabel' => __('Next Page »'), ); $args = wp_parse_args( $args, $defaults ); $max_num_pages = $wp_query->max_num_pages; $paged = get_query_var('paged'); //only have sep if there's both prev and next results if ($paged < 2 || $paged >= $max_num_pages) { $args['sep'] = ''; } if ( $max_num_pages > 1 ) { $return = get_previous_posts_link($args['prelabel']); $return .= preg_replace('/&([^#])(?![a-z]{1,8};)/i', '&$1', $args['sep']); $return .= get_next_posts_link($args['nxtlabel']); } } return $return; } |
1 2 3 4 5 6 7 8 9 10 11 12 13 | /** * Display post pages link navigation for previous and next pages. * * @since 0.71 * * @param string $sep Optional. Separator for posts navigation links. * @param string $prelabel Optional. Label for previous pages. * @param string $nxtlabel Optional Label for next pages. */ function posts_nav_link( $sep = '', $prelabel = '', $nxtlabel = '' ) { $args = array_filter( compact('sep', 'prelabel', 'nxtlabel') ); echo get_posts_nav_link($args); } |
関数 get_comments_pagenum_link()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | /** * Retrieve comments page number link. * * @since 2.7.0 * * @param int $pagenum Optional. Page number. * @return string */ function get_comments_pagenum_link( $pagenum = 1, $max_page = 0 ) { global $wp_rewrite; $pagenum = (int) $pagenum; $result = get_permalink(); if ( 'newest' == get_option('default_comments_page') ) { if ( $pagenum != $max_page ) { if ( $wp_rewrite->using_permalinks() ) $result = user_trailingslashit( trailingslashit($result) . 'comment-page-' . $pagenum, 'commentpaged'); else $result = add_query_arg( 'cpage', $pagenum, $result ); } } elseif ( $pagenum > 1 ) { if ( $wp_rewrite->using_permalinks() ) $result = user_trailingslashit( trailingslashit($result) . 'comment-page-' . $pagenum, 'commentpaged'); else $result = add_query_arg( 'cpage', $pagenum, $result ); } $result .= '#comments'; /** * Filter the comments page number link for the current request. * * @since 2.7.0 * * @param string $result The comments page number link. */ $result = apply_filters( 'get_comments_pagenum_link', $result ); return $result; } |
関数 get_next_comments_link()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | /** * Return the link to next comments page. * * @since 2.7.1 * * @param string $label Optional. Label for link text. * @param int $max_page Optional. Max page. * @return string|null */ function get_next_comments_link( $label = '', $max_page = 0 ) { global $wp_query; if ( !is_singular() || !get_option('page_comments') ) return; $page = get_query_var('cpage'); $nextpage = intval($page) + 1; if ( empty($max_page) ) $max_page = $wp_query->max_num_comment_pages; if ( empty($max_page) ) $max_page = get_comment_pages_count(); if ( $nextpage > $max_page ) return; if ( empty($label) ) $label = __('Newer Comments »'); /** * Filter the anchor tag attributes for the next comments page link. * * @since 2.7.0 * * @param string $attributes Attributes for the anchor tag. */ return '<a href="' . esc_url( get_comments_pagenum_link( $nextpage, $max_page ) ) . '" ' . apply_filters( 'next_comments_link_attributes', '' ) . '>'. preg_replace('/&([^#])(?![a-z]{1,8};)/i', '&$1', $label) .'</a>'; } |
関数 next_comments_link()
1 2 3 4 5 6 7 8 9 10 11 | /** * Display the link to next comments page. * * @since 2.7.0 * * @param string $label Optional. Label for link text. * @param int $max_page Optional. Max page. */ function next_comments_link( $label = '', $max_page = 0 ) { echo get_next_comments_link( $label, $max_page ); } |
関数 get_previous_comments_link()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | /** * Return the previous comments page link. * * @since 2.7.1 * * @param string $label Optional. Label for comments link text. * @return string|null */ function get_previous_comments_link( $label = '' ) { if ( !is_singular() || !get_option('page_comments') ) return; $page = get_query_var('cpage'); if ( intval($page) <= 1 ) return; $prevpage = intval($page) - 1; if ( empty($label) ) $label = __('« Older Comments'); /** * Filter the anchor tag attributes for the previous comments page link. * * @since 2.7.0 * * @param string $attributes Attributes for the anchor tag. */ return '<a href="' . esc_url( get_comments_pagenum_link( $prevpage ) ) . '" ' . apply_filters( 'previous_comments_link_attributes', '' ) . '>' . preg_replace('/&([^#])(?![a-z]{1,8};)/i', '&$1', $label) .'</a>'; } |
関数 previous_comments_link()
1 2 3 4 5 6 7 8 9 10 | /** * Display the previous comments page link. * * @since 2.7.0 * * @param string $label Optional. Label for comments link text. */ function previous_comments_link( $label = '' ) { echo get_previous_comments_link( $label ); } |
関数 paginate_comments_links()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | /** * Create pagination links for the comments on the current post. * * @see paginate_links() * @since 2.7.0 * * @param string|array $args Optional args. See paginate_links(). * @return string Markup for pagination links. */ function paginate_comments_links($args = array()) { global $wp_rewrite; if ( !is_singular() || !get_option('page_comments') ) return; $page = get_query_var('cpage'); if ( !$page ) $page = 1; $max_page = get_comment_pages_count(); $defaults = array( 'base' => add_query_arg( 'cpage', '%#%' ), 'format' => '', 'total' => $max_page, 'current' => $page, 'echo' => true, 'add_fragment' => '#comments' ); if ( $wp_rewrite->using_permalinks() ) $defaults['base'] = user_trailingslashit(trailingslashit(get_permalink()) . 'comment-page-%#%', 'commentpaged'); $args = wp_parse_args( $args, $defaults ); $page_links = paginate_links( $args ); if ( $args['echo'] ) echo $page_links; else return $page_links; } |