wordpress phpファイル include

・functions.php

/*================================================
php file include
================================================*/
function short_php($params = array()) {
	extract(shortcode_atts(array(
		'file' => 'default'
	), $params));
	ob_start();
	include(get_theme_root(). '/'. get_template(). "/template/$file.php");
	return ob_get_clean();
}
add_shortcode('php_inc', 'short_php');

・投稿エディタ
 例:templateフォルダ内のgmap.phpを指定

[php_inc file='gmap']

・gmap.php

<?php
$lat = '35.xxxxxx';
$lng = '136.xxxxxx';
?>

<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true&libraries=adsense"></script>
<script>
function initialize() {
	var myLatLng = new google.maps.LatLng(<?php echo $lat; ?>, <?php echo $lng; ?>);
	var mapOptions = {
		zoom: 17,
		center: myLatLng
	}
	var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
	var beachMarker = new google.maps.Marker({
		position: myLatLng,
		map: map,
	});

}
google.maps.event.addDomListener(window, 'load', initialize);
</script>

<div id="map-canvas" style="width:100%; height:400px"></div>
PAGE TOP