get_previous_posts_link

函式
get_previous_posts_link ( $label = null )
引數
  • (string) $label Optional. Previous page link text.
    Required:
    Default: null
返回值
  • (string|void) HTML-formatted previous page link.
定義位置
相關方法
get_previous_post_linkprevious_posts_linkget_previous_posts_page_linkprevious_post_linkget_previous_comments_link
引入
2.7.0
棄用
-

get_previous_posts_link函式是一個WordPress函式,用於檢索特定查詢的前一篇文章的連結: 這個函式需要一個可選的引數來表示連結文字,並返回到以前的文章的連結。

檢索上一個文章的頁面連結。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function get_previous_posts_link( $label = null ) {
global $paged;
if ( null === $label ) {
$label = __( '« Previous Page' );
}
if ( ! is_single() && $paged > 1 ) {
/**
* Filters 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>';
}
}
function get_previous_posts_link( $label = null ) { global $paged; if ( null === $label ) { $label = __( '&laquo; Previous Page' ); } if ( ! is_single() && $paged > 1 ) { /** * Filters 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>'; } }
function get_previous_posts_link( $label = null ) {
	global $paged;

	if ( null === $label ) {
		$label = __( '&laquo; Previous Page' );
	}

	if ( ! is_single() && $paged > 1 ) {
		/**
		 * Filters 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>';
	}
}

常見問題

FAQs
檢視更多 >