サポート » 使い方全般 » index.phpの記事一覧で先頭に固定を有効にしたい(通常投稿)

  • 以下の様なコードでindex.phpにおいて通常投稿の記事一覧を出力しています。

    <?php
            $args = array('post_type' => 'post', 'numberposts' => 6,'category_name' => 'diary');
            $index_recent_post=get_posts($args);
            if ($index_recent_post) :
            foreach ($index_recent_post as $post) : setup_postdata ($post);
       ?>

    先頭に固定の設定をしても先頭に固定されないのです。
    どうすればいいでしょうか?

1件の返信を表示中 - 1 - 1件目 (全1件中)
  • モデレーター jim912

    (@jim912)

    get_posts は、先頭に固定を無視するパラメータ ignore_sticky_posts が get_posts の関数内で、強制的に指定されているため、先頭に固定を利用することはできません。

    WP_Query などで代替するのが一番簡単な方法となります。

1件の返信を表示中 - 1 - 1件目 (全1件中)
  • トピック「index.phpの記事一覧で先頭に固定を有効にしたい(通常投稿)」には新たに返信することはできません。