get_next_comments_link

函式
get_next_comments_link ( $label = '', $max_page = 0 )
引數
  • (string) $label Optional. Label for link text. Default empty.
    Required:
    Default: (empty)
  • (int) $max_page Optional. Max page. Default 0.
    Required:
返回值
  • (string|void) HTML-formatted link for the next page of comments.
定義位置
相關方法
next_comments_linkget_edit_comment_linkget_comments_linkget_comment_linkget_next_posts_link
引入
2.7.1
棄用
-

get_next_comments_link函式用於生成一個指向文章的下一頁評論的連結: 這個函式通常用於文章的評論部分,以提供評論頁之間的導航。

檢索到下一個評論頁面的連結。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function get_next_comments_link( $label = '', $max_page = 0 ) {
global $wp_query;
if ( ! is_singular() ) {
return;
}
$page = get_query_var( 'cpage' );
if ( ! $page ) {
$page = 1;
}
$nextpage = (int) $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 »' );
}
/**
* Filters 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>';
}
function get_next_comments_link( $label = '', $max_page = 0 ) { global $wp_query; if ( ! is_singular() ) { return; } $page = get_query_var( 'cpage' ); if ( ! $page ) { $page = 1; } $nextpage = (int) $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 &raquo;' ); } /** * Filters 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>'; }
function get_next_comments_link( $label = '', $max_page = 0 ) {
	global $wp_query;

	if ( ! is_singular() ) {
		return;
	}

	$page = get_query_var( 'cpage' );

	if ( ! $page ) {
		$page = 1;
	}

	$nextpage = (int) $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 &raquo;' );
	}

	/**
	 * Filters 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>';
}

常見問題

FAQs
檢視更多 >