0

特定のカテゴリの最新の投稿とともに特定の静的ページを照会する方法は?

http://codex.wordpress.org/Class_Reference/WP_Query

4

1 に答える 1

2

そのためには、テンプレートを作成する必要があります。

それを特定のページに渡します。

そのテンプレートで、特定のカテゴリの投稿を呼び出すコードを以下に示します。

これを試して:

<?php

        $args2 = array(
            'numberposts' => 1,
            'cat' => 4,
            'orderby' => 'date',
            'order' => 'DESC',
            'post_type' => 'post',
            'post_parent' => '',
            'post_status' => 'publish',
            'suppress_filters' => true
        );
        $homepage_content = get_posts($args2);

        foreach ($homepage_content as $key => $value) {
            echo "<h2>" . $value->post_title . "</h2>";
            echo $value->post_content;
            $post_id = $value->ID;
        }

?>

ここでは cat 引数に Category の ID を渡すだけです。

For more reference: http://codex.wordpress.org/Template_Tags/get_posts 

- ありがとう

于 2013-11-06T05:42:30.690 に答える