私はずっと前と非常に似たようなことをしましたが、私はそれを不正行為でやっていました。
組み込みの書き換えルールが複雑すぎる、または実行できない場合は、要求をキャッチして結果をフィルタする方が簡単です。簡易版:
add_action('parse_request', 'my_parse_request');
function my_parse_request (&$wp) {
$path = $wp->request;
$groups = array();
if (preg_match("%shop/product/([a-zA-Z0-9-]+)%", $path, $groups)) {
$code = $groups[1];
$product = get_product($code); // your own code here
if (isset($product)) {
add_filter('the_posts', 'my_product_filter_posts');
}
}
}
function my_product_filter_posts ($posts) {
ob_start();
echo "stuff goes here"; // your body here
$content = ob_get_contents();
ob_end_clean();
return array(new DummyResult(0, "Product name", $content));
}
が説明するのは:
parse_request
上のアクションはデータベース検索前に呼び出されます。 URLに基づいて、他のアクションとフィルタがインストールされます。
投稿のフィルタは、データベースルックアップの結果を偽の結果に置き換えます。
DummyResultは、単純なポストと同じフィールドを持つクラス、またはそれを離れて得るためにそれらのちょうど十分である:リーダ放置宿題がたくさんあります
class DummyResult {
public $ID;
public $post_title;
public $post_content;
public $post_author;
public $comment_status = "closed";
public $post_status = "publish";
public $ping_status = "closed";
public $post_type = "page";
public $post_date = "";
function __construct ($ID, $title, $content) {
$this->ID = $ID;
$this->post_title = $title;
$this->post_content = $content;
$this->post_author = get_default_author(); // implement this function
}
}
それは醜い、働くアプローチです。 template_redirect
のフィルタを追加して、通常のページテンプレートを製品固有のテンプレートに置き換えることをお勧めします。かなりのパーマリンクが必要な場合は、URL正規表現を調整する必要があります。