コンテンツにスキップ

WordPressテーマの移植

WordPressテーマは体系的にEmDashに変換できます。視覚デザイン、コンテンツ構造、動的機能はすべて、3段階のアプローチを使用して移行されます。

  1. デザイン抽出

    WordPressテーマからCSS変数、フォント、色、レイアウトパターンを抽出します。ライブサイトを分析して、計算済みスタイルとレスポンシブブレークポイントをキャプチャします。

  2. テンプレート変換

    PHPテンプレートをAstroコンポーネントに変換します。WordPressテンプレート階層をAstroルートにマッピングし、テンプレートタグをEmDash API呼び出しに変換します。

  3. 動的機能

    ナビゲーションメニュー、ウィジェットエリア、タクソノミー、サイト設定をそれぞれのEmDash相当のものに移植します。完全なコンテンツモデルをキャプチャするシードファイルを作成します。

ファイル目的
style.cssテーマヘッダーを含むメインスタイルシート
assets/css/追加のスタイルシート
theme.jsonブロックテーマ(WP 5.9+) - 構造化されたトークン
WordPressパターンEmDash変数
本文フォントファミリー--font-body
見出しフォント--font-heading
プライマリカラー--color-primary
背景--color-base
テキストカラー--color-contrast
コンテンツ幅--content-width

抽出したCSS変数、ヘッダー/フッター構造、フォント読み込み、レスポンシブブレークポイントを含む src/layouts/Base.astro を作成します:

src/layouts/Base.astro
---
import { getSiteSettings, getMenu } from "emdash";
import "../styles/global.css";
const { title, description } = Astro.props;
const settings = await getSiteSettings();
const primaryMenu = await getMenu("primary");
const pageTitle = title ? `${title} | ${settings.title}` : settings.title;
---
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>{pageTitle}</title>
</head>
<body>
<header>
{settings.logo ? (
<img src={settings.logo.url} alt={settings.title} />
) : (
<span>{settings.title}</span>
)}
<nav>
{primaryMenu?.items.map((item) => (
<a href={item.url}>{item.label}</a>
))}
</nav>
</header>
<main><slot /></main>
</body>
</html>

テンプレート階層のマッピング

Section titled “テンプレート階層のマッピング”
WordPressテンプレートAstroルート
index.phpsrc/pages/index.astro
single.phpsrc/pages/posts/[slug].astro
single-{post_type}.phpsrc/pages/{type}/[slug].astro
page.phpsrc/pages/[...slug].astro
archive.phpsrc/pages/posts/index.astro
category.phpsrc/pages/categories/[slug].astro
tag.phpsrc/pages/tags/[slug].astro
search.phpsrc/pages/search.astro
404.phpsrc/pages/404.astro
header.php / footer.phpsrc/layouts/Base.astroの一部
sidebar.phpsrc/components/Sidebar.astro

テンプレートタグのマッピング

Section titled “テンプレートタグのマッピング”
WordPress関数EmDash相当
have_posts() / the_post()getEmDashCollection()
get_post()getEmDashEntry()
the_title()post.data.title
the_content()<PortableText value={post.data.content} />
the_excerpt()post.data.excerpt
the_permalink()/posts/${post.slug}
the_post_thumbnail()post.data.featured_image
get_the_date()post.data.publishedAt
get_the_category()getEntryTerms(coll, id, "categories")
get_the_tags()getEntryTerms(coll, id, "tags")
php title="archive.php"
<?php while (have_posts()) : the_post(); ?>
<article>
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</h2>
<?php the_excerpt(); ?>
</article>
<?php endwhile; ?>
php title="single.php"
<?php get_header(); ?>
<article>
<h1><?php the_title(); ?></h1>
<?php the_content(); ?>
<div class="post-meta">
Posted in: <?php the_category(', '); ?>
</div>
</article>
<?php get_footer(); ?>

WordPressの get_template_part() 呼び出しは、Astroコンポーネントのインポートになります。 template-parts/content-post.php パーシャルは、ループ内でインポートしてレンダリングする PostCard.astro コンポーネントになります。

functions.php 内のメニューを特定し、対応するEmDashメニューを作成します:

astro title="src/components/PrimaryNav.astro"
---
import { getMenu } from "emdash";
const menu = await getMenu("primary");
---
{menu && (
<nav class="primary-nav">
<ul>
{menu.items.map((item) => (
<li>
<a href={item.url} aria-current={Astro.url.pathname === item.url ? "page" : undefined}>
{item.label}
</a>
{item.children.length > 0 && (
<ul class="submenu">
{item.children.map((child) => (
<li><a href={child.url}>{child.label}</a>
</li>
))}
</ul>
)}
</li>
))}
</ul>
</nav>
)}

ウィジェットエリア(サイドバー)

Section titled “ウィジェットエリア(サイドバー)”

テーマ内のウィジェットエリアを特定し、レンダリングします:

astro title="src/components/Sidebar.astro"
---
import { getWidgetArea, getMenu } from "emdash";
import { PortableText } from "emdash/ui";
import RecentPosts from "../../themes/widgets/RecentPosts.astro";
const sidebar = await getWidgetArea("sidebar");
const widgetComponents = { "core:recent-posts": RecentPosts };
---
{sidebar && sidebar.widgets.length > 0 && (
<aside class="sidebar">
{sidebar.widgets.map(async (widget) => (
<div class="widget">
{widget.title && <h3>{widget.title}</h3>
}
{widget.type === "content" && <PortableText value={widget.content} />}
{widget.type === "menu" && (
<nav>
{await getMenu(widget.menuName).then((m) =>
m?.items.map((item) => <a href={item.url}>{item.label}</a>
)
)}
</nav>
)}
{widget.type === "component" && widgetComponents[widget.componentId] && (
<Fragment>
{(() => {
const Component = widgetComponents[widget.componentId];
return <Component {...widget.componentProps} />;
})()}
</Fragment>
)}
</div>
))}
</aside>
)}

ウィジェットタイプマッピング

Section titled “ウィジェットタイプマッピング”
WordPress ウィジェットEmDash ウィジェットタイプ
テキスト/カスタムHTMLtype: "content"
カスタムメニューtype: "menu"
最近の投稿component: "core:recent-posts"
カテゴリーcomponent: "core:categories"
タグクラウドcomponent: "core:tag-cloud"
検索component: "core:search"

テーマに登録されたタクソノミーをクエリします:

astro title="src/pages/genres/[slug].astro"
---
import { getTaxonomyTerms, getEntriesByTerm } from "emdash";
import Base from "../../../layouts/Base.astro";
export async function getStaticPaths() {
const genres = await getTaxonomyTerms("genre");
return genres.map((genre) => ({
params: { slug: genre.slug },
props: { genre },
}));
}
const { genre } = Astro.props;
const books = await getEntriesByTerm("books", "genre", genre.slug);
---
<Base title={genre.label}>
<h1>{genre.label}</h1>
{books.map((book) => (
<article>
<h2><a href={`/books/${book.slug}`}>{book.data.title}</a>
</h2>
</article>
))}
</Base>
WordPress カスタマイザーEmDash 設定
サイトタイトルtitle
キャッチフレーズtagline
サイトアイコンfavicon
カスタムロゴlogo
1ページあたりの投稿数postsPerPage

ショートコードから Portable Text へ

Section titled “ショートコードから Portable Text へ”

WordPress ショートコードは Portable Text カスタムブロックになります:

php title="functions.php"
add_shortcode('gallery', function($atts) {
$ids = explode(',', $atts['ids']);
return '<div class="gallery">...</div>
';
});

シードファイルに完全なコンテンツモデルをキャプチャします。設定、タクソノミー、メニュー、ウィジェットエリアを含めます:

json title=".emdash/seed.json"
{
"$schema": "https://emdashcms.com/seed.schema.json",
"version": "1",
"meta": { "name": "移植したテーマ" },
"settings": { "title": "私のサイト", "tagline": "ようこそ", "postsPerPage": 10 },
"taxonomies": [
{
"name": "category",
"label": "カテゴリー",
"hierarchical": true,
"collections": ["posts"]
}
],
"menus": [
{
"name": "primary",
"label": "メインナビゲーション",
"items": [
{ "type": "custom", "label": "ホーム", "url": "/" },
{ "type": "custom", "label": "Blog", "url": "/posts" }
]
}
],
"widgetAreas": [
{
"name": "sidebar",
"label": "メインサイドバー",
"widgets": [
{
"type": "component",
"componentId": "core:recent-posts",
"props": { "count": 5 }
}
]
}
]
}

完全な仕様については シードファイル形式 を参照してください。

フェーズ1(デザイン): CSS変数を抽出、フォントの読み込み、カラースキームの一致、レスポンシブブレークポイントが機能。

フェーズ2(テンプレート): ホームページ、個別投稿、アーカイブ、404ページがすべて正しくレンダリング。

フェーズ3(動的): サイト設定が構成済み、メニューが機能、タクソノミーがクエリ可能、ウィジェットエリアがレンダリング、シードファイルが完成。

テーマに親テーマがある場合(style.css の Template: を確認)、まず親テーマを分析し、その後子テーマのオーバーライドを適用します。

WordPress 5.9+ のブロックテーマは、デザイントークンに theme.json を、ブロックマークアップに templates/*.html を使用します。ブロックマークアップを Astro コンポーネントに変換し、theme.json からトークンを抽出します。

Elementor、Divi などで構築されたコンテンツは、テーマファイルではなく投稿メタに保存されます。このコンテンツはテーマ移植ではなく WXR 経由でインポートされます。テーマ移植ではシェルに焦点を当て、ページビルダーコンテンツはインポート後に Portable Text を通じてレンダリングされます。