wordpress phpファイル include
・functions.php
01 02 03 04 05 06 07 08 09 10 11 12 | /*================================================ 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を指定
1 | [php_inc file='gmap'] |
・gmap.php
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | <?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> |