wp_rss

函式
wp_rss ( $url, $num_items = -1 )
引數
  • (string) $url URL of feed to display. Will not auto sense feed URL.
    Required:
  • (int) $num_items Optional. Number of items to display, default is all.
    Required:
    Default: -1
定義位置
相關方法
wp_kseswp_roleswp_slashwp_styleswp_robots
引入
1.5.0
棄用
-

wp_rss: 這是一個WordPress的函式,用來顯示一個網站的RSS提要。它根據網站的內容生成RSS提要,並可以使用過濾器和鉤子進行定製。

在一個HTML有序列表中顯示所有RSS專案。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function wp_rss( $url, $num_items = -1 ) {
if ( $rss = fetch_rss( $url ) ) {
echo '<ul>';
if ( $num_items !== -1 ) {
$rss->items = array_slice( $rss->items, 0, $num_items );
}
foreach ( (array) $rss->items as $item ) {
printf(
'<li><a href="%1$s" title="%2$s">%3$s</a></li>',
esc_url( $item['link'] ),
esc_attr( strip_tags( $item['description'] ) ),
esc_html( $item['title'] )
);
}
echo '</ul>';
} else {
_e( 'An error has occurred, which probably means the feed is down. Try again later.' );
}
}
function wp_rss( $url, $num_items = -1 ) { if ( $rss = fetch_rss( $url ) ) { echo '<ul>'; if ( $num_items !== -1 ) { $rss->items = array_slice( $rss->items, 0, $num_items ); } foreach ( (array) $rss->items as $item ) { printf( '<li><a href="%1$s" title="%2$s">%3$s</a></li>', esc_url( $item['link'] ), esc_attr( strip_tags( $item['description'] ) ), esc_html( $item['title'] ) ); } echo '</ul>'; } else { _e( 'An error has occurred, which probably means the feed is down. Try again later.' ); } }
function wp_rss( $url, $num_items = -1 ) {
	if ( $rss = fetch_rss( $url ) ) {
		echo '<ul>';

		if ( $num_items !== -1 ) {
			$rss->items = array_slice( $rss->items, 0, $num_items );
		}

		foreach ( (array) $rss->items as $item ) {
			printf(
				'<li><a href="%1$s" title="%2$s">%3$s</a></li>',
				esc_url( $item['link'] ),
				esc_attr( strip_tags( $item['description'] ) ),
				esc_html( $item['title'] )
			);
		}

		echo '</ul>';
	} else {
		_e( 'An error has occurred, which probably means the feed is down. Try again later.' );
	}
}

常見問題

FAQs
檢視更多 >