wp_get_recent_posts

Sponsored Link

最近の投稿を取得します。

Sponsored Link

Retrieve the recent posts.

wp_get_recent_postsのファンクションタグ使用方法

<?php wp_get_recent_posts( $args ) ?>

概要

<?php $args = array(
    'numberposts' => 10,
    'offset' => 0,
    'category' => 0,
    'orderby' => 'post_date',
    'order' => 'DESC',
    'include' => ,
    'exclude' => ,
    'meta_key' => ,
    'meta_value' =>,
    'post_type' => 'post',
    'post_status' => 'draft, publish, future, pending, private',
    'suppress_filters' => true ); ?>

戻り値

(array)
投稿の配列のリスト。投稿オブジェクトの配列を返すget_postsとは異なる。

(array)
List of posts arrays. Different from get_posts which returns an array of post objects.

wp_get_recent_postsのパラメーター

WP_Queryパラメータを使用します。

Uses WP_Query Parameters.

これは最新10件の投稿リストを表示するためにwp_get_recent_posts()関数を使用する方法を示す例です。

This is an example that show how to use the wp_get_recent_posts() function to list the recent 10 posts.

Recent Posts

大体の最近の投稿の範囲を定めたい場合、この下記の例のようにファンクションパラメータに数値を記入する必要があります。

If you want to delimit more or less recent posts you have to put the number in the function parameter like this example bellow:

<h2>Recent Posts</h2>
<ul>
<?php
	$args = array( 'numberposts' => '5' );
	$recent_posts = wp_get_recent_posts( $args );
	foreach( $recent_posts as $recent ){
		echo '<li><a href="' . get_permalink($recent&#91;"ID"&#93;) . '" title="Look '.$recent&#91;"post_title"&#93;.'" >' .   $recent["post_title"].'</a></li> ';
	}
?>
</ul>

注釈

  • Uses: wp_parse_args()
  • Uses: get_posts()

変更ログ

Since: 1.0.0
3.1.0: The $num parameter deprecated in favor of $args.

ソースファイル

wp_get_recent_posts()は、wp-includes/post.php内に位置しています。

wp_get_recent_posts() is located in wp-includes/post.php.

Sponsored Link