Last active
April 10, 2018 04:33
-
-
Save na0x2c6/9b7b48652fb4f93599267a16abe60856 to your computer and use it in GitHub Desktop.
【改訂版】WordPressテーマを一般ファイルで使う ref: https://qiita.com/cellolism/items/4d06ff73779c8da2e170
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<IfModule mod_rewrite.c> | |
### WordPress 用 #### | |
RewriteEngine On | |
RewriteBase / | |
RewriteRule ^index\.php$ - [L] | |
RewriteCond %{REQUEST_FILENAME} !-f | |
RewriteCond %{REQUEST_FILENAME} !-d | |
RewriteRule ^index\.php$ - [L] | |
##################### | |
#### ハンドラファイル用 #### | |
# http://hoge.com/foo.htmlをhttp://hoge.com/foo/でアクセスさせる | |
RewriteCond %{REQUEST_FILENAME}\.html -f | |
RewriteRule . /render.php [L] | |
# ちなみにfoo.htmlでそのままアクセスさせたいときは下記 | |
# RewriteRule \.html$ /handler.php [L] | |
RewriteCond %{REQUEST_FILENAME} -d | |
RewriteRule . /render.php [L] | |
####################### | |
</IfModule> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function get_requested_static_file() { | |
$dir = dirname($_SERVER['REQUEST_URI']);// . '/'; | |
if ($dir != '/') { | |
$dir .= '/'; | |
} | |
$file = basename($_SERVER['REQUEST_URI']); | |
$filepath = $_SERVER['DOCUMENT_ROOT'] . $dir . $file; | |
$requested_file = ''; | |
if(file_exists($filepath . '.html')) | |
{ | |
$requested_file = $filepath . '.html'; | |
} | |
else if(file_exists($filepath)) | |
{ | |
$requested_file = $filepath . '/index.html'; | |
} | |
return $requested_file; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php $_title = 'テスト' ?> | |
<h1>hello, world!</h1> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$dir = dirname($_SERVER['REQUEST_URI']); | |
if ($dir != '/') { | |
$dir .= '/'; | |
} | |
$file = basename($_SERVER['REQUEST_URI']); | |
$filepath = $_SERVER['DOCUMENT_ROOT'] . $dir . $file; | |
$static_file = ''; | |
if(is_dir($filepath)) | |
{ | |
$static_file = $filepath . '/index.html'; | |
} | |
else if(file_exists($filepath . '.html')) // URLに.htmlを含めたいときは、$filepathだけでいい | |
{ | |
$static_file = $filepath . '.html'; | |
} | |
ob_start(); // 出力先をここからバッファに向ける | |
include($static_file); // $_titleの取得もここで | |
$_contents = ob_get_contents(); // バッファのコンテンツを保持 | |
ob_end_clean(); // バッファを破棄 | |
// original フラグがあればそのまま出力 | |
if(isset($_original) && $_original) { | |
echo $_contents; | |
return; | |
} | |
require_once ('./wp-blog-header.php'); | |
add_filter( 'document_title_parts', function ($title) use ($_title) { | |
$title['title'] = $_title; | |
return $title; | |
} | |
); | |
get_header(); | |
?> | |
<div id="primary" class="content-area"> | |
<main id="main" class="site-main" role="main"> | |
<?php include($load_file); ?> | |
</main><!-- .site-main --> | |
<?php echo( $_contents ); /* コンテンツ出力 */ ?> | |
</div><!-- .content-area --> | |
<?php get_sidebar(); ?> | |
<?php get_footer(); ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment