0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

[microCMS] フロントエンドで記事の並び順を指定する

0
Posted at

microCMSから記事一覧といったコンテンツを取得した時、並び順は管理画面のコンテンツの表示順となります。
ブログの記事一覧のように日付順で並ばせたい場合はパラメーターを指定する必要があります。

やりたいこと

最新記事一覧、カテゴリごとの記事一覧で、記事を公開日時の新しい順にする

ドキュメント

公開日時の降順で並び替えをするパラメーター

orders=-publishedAt

コード例

https://github.com/microcmsio/nextjs-simple-blog-template/blob/main/libs/microcms.ts#L50-L59
配布されているテンプレートを利用する場合、下記の部分を変更すればOK

// ブログ一覧を取得
export const getList = async (queries?: MicroCMSQueries) => {
  const listData = await client
    .getList<Blog>({
      endpoint: 'blog',
      // テンプレート内で個別に指定するクエリを生かしつつ、デフォルトは公開日時の降順とする
      queries: {
        orders: '-publishedAt',
        ...queries,
      },
    })
    .catch(notFound);
  return listData;
};

スクリーンショット 2026-11-13 9.39.52.png

現場からは以上です

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?