😍Study Cms Wordpress Nextjs (ok)

Step 1: Config env

next.config.ts

if (!URL.canParse(process.env.WORDPRESS_API_URL as string)) {
  throw new Error(`Please provide a valid WordPress instance URL.Add to your environment variables WORDPRESS_API_URL.`);
}
const { protocol, hostname, port, pathname } = new URL(process.env.WORDPRESS_API_URL as string);
import type { NextConfig } from "next";
const nextConfig: NextConfig = {
  reactStrictMode: true,
  images: {
    domains: [
      'wpclidemo.dev',
      "2.gravatar.com",
      "0.gravatar.com",
      "secure.gravatar.com",
    ],
    remotePatterns: [
      {
        protocol: 'https',
        hostname: 'wpclidemo.dev',
        port: '',
        pathname: '**',
      },
    ],
  },
};
export default nextConfig;

Step 2: Create Home Page

pages\_document.tsx

pages\_app.tsx

constants\index.ts

components\layout.tsx

components\header.tsx

components\main.tsx

components\footer.tsx

components\layout.tsx

components\container.tsx

components\intro.tsx

pages\index.tsx

.env.local

Step 3: getAllPostsForHome

apis\index.ts

pages\index.tsx

Step 3.1: HeroPost

pages\index.tsx

components\hero-post.tsx

components\cover-image.tsx

components\date.tsx

components\avatar.tsx

Step 3.2 MorePost

pages\index.tsx

components\more-stories.tsx

components\post-preview.tsx

Step 4: Detail Post

pages\posts[slug].tsx

apis\index.ts

components\post-title.tsx

components\post-header.tsx

components\post-body.tsx

Step 4.1 Tags

pages\posts\[slug].tsx

components\tags.tsx

250KB
archive
Open

Step 4.1 Xử lý trường hợp không có post thật trên đường dẫn

pages\posts\[slug].tsx

Step 4.2 MorePost

pages\posts\[slug].tsx

Step 5 Viết lại template để phù hợp cho việc làm menu

Lý do vì do bản trước không sử dụng template chung cho toàn trang giờ chuyển sang file pages_app.tsx có dạng sau:

components\layout.tsx

pages\_app.tsx

250KB
archive
Open

Last updated

Was this helpful?