私は次のJavaScriptjavascriptでwordpress php関数を使う方法は?
var val;
function OnChangeSelect()
{
var e=document.getElementById("typeselect");
val = e.value;
if(val==2)
{
document.getElementById("formbody").innerHTML ="<?php get_template_part("+"publish_game_nr"+");?>";
}
else
{
document.getElementById("formbody").innerHTML ="<?php get_template_part("+"publish_game_fe"+");?>";
}
}
にリンクして、テンプレートのルートディレクトリ
<?php
/**
**
* Template Name: publish
*
* @package WordPress
* @subpackage Twenty_Fourteen
* @since Twenty Fourteen 1.0
*/
?>
<link rel="stylesheet" type="text/css" href="../Asset/css/style.css">
<script src="../Asset/scripts/script.js"></script>
<?php
get_header(); ?>
<div class="col-md-12">
<div style="background-color: #D3D3D3;height:1px;"></div>
</div>
<div id="primary" class="content-area">
<main id="main" class="site-main site-main--single" role="main">
<div class="container-fluid">
<div class="col-md-5"></div>
<div class="col-md-2">
<div align="center" >
<select id="typeselect" name="value" onChange="OnChangeSelect()">
<option value="1">Featured</option><br />
<option value="2">General</option><br />
</select>
</div>
</div><!-- type select-->
<div class="col-md-12">
<div style="background-color: #D3D3D3;height:1px;margin:5px"></div>
</div>
<div id="formbody" class="col-md-12">
<!-- include php files here -->
</div>
<script>OnChangeSelect()</script>
</div><!-- container -->
</main> <!-- #main -->
</div> <!-- #primary -->
<?php //get_sidebar(); ?>
<?php get_footer(); ?>
でカスタムページpublish.phpを持っている私は
<div id="formbody" class="col-md-12">
<!-- include php files here -->
</div>
の内側に内容を変更したいですプルダウンメニューで選択したオプションに基づいてpublish.php
ので、私は2つのseprate PHPファイルpublish_game_nr.php
とjavascript
でpublish_game_fe.php
がdiv
のinnerhtml
がwordpress
get_template_part()
を使用してこれらのPHP
ファイルを含めるように変更しようとしていますを作成しましたが、ファイルがロードされません。私がdiv
タグで直接関数を使用すると。ファイルが正常に読み込まれます
これを行う正しい方法は何ですか?
を使用しました動作していない –