WordPress Integrator
MODxには最初から簡単なblog機能(NewsPublisher, NewsListing, NewsFeed)が付属し、ちょっとしたサイトのメモ程度に使うには重宝します。
しかしblogを主眼に開発されたソフトウェアに比べると機能的に見劣りすることも確かです。
そこで、共通部分はシンプルでありながら、プラグインを追加して自由にカスタマイズできるブログWordPress (ME)をMODxを通して使えるよう、プラグインとスニペットを用意しました。
WordPressのプラグインは大方使えると思います。WordPressが吐いたものをMODxに取り込んでいるので、MODxのタグを出力すればスニペットやチャンクも使えます。(WordPressのテンプレート中にも書けます)。
WordPress ME 2.1.3 + MODx 0.9.5 で WordPress Integrator 1.2.0, 1.1.0 の動作を確認。
※ 1.0.0以下はプラグインに余分な< ?phpが入っています。削除して使ってください。
ダウンロード
| バージョン/DL | 日付 | 概要 |
|---|---|---|
| 1.2.0 | 2007 04/21 | alias path support with WordPress Router |
| 1.1.0 | 2007 04/18 | alias path support |
過去のバージョン
| 更新 | バージョン | 備考 |
|---|---|---|
| 20070213 | 1.0.1 | WordPress 2.1 support |
| 20061225 | 1.0.0 | latest post support( &block=latest ) |
| 20061128 | 0.0.2 | MODx placeholders support |
| 20061126 | 0.0.1 | minor fix, modx2wp.php added |
| 20061125 | 0.0.0 | new |
イベントトリガの設定
| URL解決方法 | OnWebPageInit | OnPageNotFound |
|---|---|---|
| フレンドリーURL + エイリアスパス | △(入口ページのみ) | ◎ |
| フレンドリーURL のみ | ◎ | ○(OnWebPageInitより高負荷) |
| フレンドリーURL OFF | ◎ | ○(同上) |
インストール
以下の解説は1.2.0を対象にしています。特に1.0.1以下では内容が異なることがあります。
MODxのルートはhttp://example.com/modx/, WordPressインストール先はhttp://example.com/modx/wp/, MODxを通してWordPressにアクセスするURIはhttp://example.com/modx/blog/とします。
MODxとWordPressのデータベースについて
MODxとWordPressの使用するデータベースが異なる場合、動作しません。
WordPressのパスとWORDPRESS_ALIASについて
MODxのフレンドリーURLに処理が渡るのは、URIに対応するパスが存在しない(!-f, !-d)場合に限られるため、実際のファイルシステム上にWORDPRESS_ALIASで指定する'blog'等のファイルやディレクトリが存在しないように注意してください。
すなわち、http://example.com/modx/wpでMODxに埋め込んだWPを扱う場合は、WordPressが実際に/public_html/modx/wpに存在してはいけません。
WordPressのインストール
日本語化版を落としてきて展開・アップロードします。DBが文字化けする場合は/wp-includes/wp-db.phpのmysql_connect直下のif文の後(
$this->select($dbname);の直前)にmysql_query("SET NAMES UTF8;", $this->dbh);と書いておきます。諸々の設定を済ませ、次へ。WordPressの修正
(多分2.1以上の)WordPressでは修正が必要となります。
/wp-settings.phpの"=&"となっている部分をすべて"="に置換してください。
プラグインの導入
WordPressRouterプラグインを導入します。 起動イベントは上述の表の通りにします。
define ('PAGE_WP_TOP', '200'); //下で作成するドキュメントのID define ('WORDPRESS_ALIAS', 'blog'); // MODxを通してアクセスする際のWordPressのエイリアスをここで定めるを自分の環境に合わせて設定します。スニペットの導入
WordPressIntegratorスニペットを導入します。設定項目は以下。
define ('WPMODX_WP_PATH', '/var/www/username/public_html/wp'); //実際にWordPressがインストールされているディレクトリWordPress用ドキュメント作成
コンテンツ>ドキュメントの作成 からドキュメントを作成します。内容は
[!WordPressIntegrator!]とします。このドキュメント自体のエイリアスやIDでアクセスすることはできない(上で設定したWORDPRESS_ALIASが使われるため、両者を一致させれば実質的には可能)ので注意。サイドバーの追加
サイドバーが必要なら、テンプレートなどに
[!WordPressIntegrator?block=sidebar!]と記入します。一部のテーマでは、テンプレートのファイルごとのタグ整合性が取れていないので、場合によっては自分で修正する必要があります。最新の一件表示
Homeなどで最新の一件を表示させたい場合は、
[!WordPressIntegrator?block=latest!]とします。1.0.0から汚いhackで「次へ」のリンク先が正しくなるようにしました。WordPressの設定
- オプション » 表示設定 » ブラウザの要求に応じて投稿内容を圧縮する (gzip)
- オフ
- オプション » 一般設定 » WordPress のアドレス (URI)
- http://example.com/wp(実際にWordPressがあるURI.大抵は正しいので変更しない)
- オプション » 一般設定 » ホームページアドレス (URI)
- http://example.com/modx/blog(MODxにWORDPRESS_ALIASをつけたもの)
プレースホルダの使用
0.0.2からMODxのプレースホルダを設定するようにしました。 スニペットを呼び出したドキュメントで、WordPressのbloginfo()で取得できる
wp_home wp_wpurl wp_description wp_rdf_url wp_rss_url wp_rss2_url wp_atom_url wp_comments_rss2_url wp_pingback_url wp_stylesheet_url wp_stylesheet_directory wp_template_directory wp_template_url wp_admin_email wp_charset wp_html_type wp_version wp_name
と、ページタイトルの設定されたwp_pagetitle
が使えます。
ドキュメントのタイトルに[+wp_pagetitle+]を含めると便利です。
WordPress (ME 2.0.5)の修正
このWordPressIntegratorを使っていると必然的に発生する現象ですが、投稿管理画面のnext/prevのリンク先がおかしくなるというWordPress (ME 2.0.5)の不具合があります。 WordPress管理画面のnext/prevリンク先修正のパッチを適用するなどして修正したほうが良いでしょう。
不具合等
- エイリアスパスONで404 Not Foundが表示される
WordPressRouterのイベントを適切に設定すれば回避できます。 上述の表を参照してください。
エイリアスパスONはあまり素敵な機能ではないので、 7bit | MODx 0.9.5 エイリアスパスの制約を受けずに便利にアクセス の様な変更をMODxに加えてしまった方が良いかもしれません。但し、Wayfinder等との兼ね合いで不具合も発生するようですので、導入の際は気をつけてください。(そもそもコア変更はあまり推奨されません)
- サイドバー(やdiv id="content")の位置がずれる
- WordPressのテンプレートがUTF-8で記述されている場合、BOM(EF BB BF)が先頭に含まれていると発生します(別にMODx+WordPressに限った話ではありません)。テキストエディタの設定でBOMを除去するか、バイナリエディタなどを用いて先頭3バイトを消します。
- トップページなどでは動作しているようだが、個別ページ(http://example.com/2007/03/14/modx/)でMODxの404ページになる
- プラグインが動いていません。先頭末尾にが付いていたら除去し、適切なトリガ(OnWebPageInitやOnPageNotFound)にチェックが入っているか確認してください。
- Fatal error: Call to a member function
WordPressのアップグレード後などで、WordPressIntegratorにない新しいグローバル変数が追加された場合に、Fatal error: Call to a member function ~といったエラーが発生することがあります。 該当の変数名を調べ、スニペットにglobal宣言を追加すれば解決します。
何か不明な点があれば掲示板などで訊いてください。(WordPressにはあまり明るくありませんが)
English Instruction
This is a copy of http://modxcms.com/forums/index.php/topic,13054.msg86329.html#msg86329 WordPress Integrator 1.0.1 instruction
1. What is "WordPress Integrator"?
WordPress Integrator (WPI) is a set of a snippet (WordPressIntegrator) and a plugin (WordPressRouter).
Former captures the output of your WordPress. Latter will seize requested URL like
http://example.com/wpi_blog/2007/03/15/howtousewpi and call the document where WordPressIntegrator-snippet is placed.
2. Requirements
* MODx 0.9.5
* WordPress 2.0.5, ME 2.1.2 (some modification required)
mod_rewrite and friendly URL (but NOT aliath path) is also required.
3. How to use
3-1. download the wordpressintegrator.1.0.1.zip from http://nanabit.net/modx/wordpress-integrator.html
3-2. make a document which should be the "interface" of WPI. (ex. id=200)
3-3. copy the snippet and name WordPressIntegrator. WPMODX_WP_PATH should be the absolute path of your WP. WPMODX_TITLE is your blog's title.
3-4. write [!WordPressIntegrator!] in document(#200).
If you would like, add [!WordPressIntegrator?block=latest!] in top page, and [!WordPressIntegrator?block=sidebar!] for sidebar.
3-5. make a plugin named WordPressRouter and check "OnWebPageInit". PAGE_WP_TOP is your interface-document's ID. (200 for the example above).
WORDPRESS_ALIAS is the alias to snach from MODx. (wpi_blog for the example above)
note that http://example.com/wpi_blog/ should NOT exists (oftenly, problems are caused by WordPress placed in http://example.com/wpi_blog/.
please upload WordPress in another path, like http://example.com/wp/)
3-6. login to WordPress admin page (Options>>General). set "WordPress address" to http://example.com/wp/,
"Blog Address" to http://example.com/wpi_blog/. Uncheck gzip option.
3-7. WordPress modification. replace all "&=" to "=" in wp-settings.php
3-8. You can use or some placeholders in the document.
4. Known Problems and Solutions
Q. [!WordPressIntegrator?block=latest!] in the top page works, but the "interface" page does not.
A. Something is wrong about the plugin.
Q. I would like to use alias path
A. patch at here http://nanabit.net/blog/2006/12/19/alias-path-like-handling/ would help. (still ensure aliash path is off)
It makes MODx generate path like alias path, and recognize URLs more flexiblly than alias path.
Moreover, directories' URL will be like http://example.com/directory/ instead of http://example.com/directory.html
Q. It doesn't work anyway!
A. Probably Ditto2 or Jot are easier to use. I would like to try them, too.

