Php 를 사용하여 그런이야길 방문자 국가 it 에서 WordPress 의 PHP 코드 페이지 표시할 때 저는 워드프레스 페이지스버트 추가 또는 포스트 it 제게 오류:. Wordpress 페이지에서든 게시물로의 PHP 코드를 추가할 수 있겠느냐.
<?PHP
try{
function visitor_country()
{
$client = @$_SERVER['HTTP_CLIENT_IP'];
$forward = @$_SERVER['HTTP_X_FORWARDED_FOR'];
$remote = $_SERVER['REMOTE_ADDR'];
$result = "Unknown";
if(filter_var($client, FILTER_VALIDATE_IP))
{
$ip = $client;
}
elseif(filter_var($forward, FILTER_VALIDATE_IP))
{
$ip = $forward;
}
else
{
$ip = $remote;
}
$ip_data = @json_decode(file_get_contents("http://www.geoplugin.net/json.gp?ip=".$ip));
if($ip_data && $ip_data->geoplugin_countryName != null)
{
$result = array('ip'=>$ip,
'continentCode'=>$ip_data->geoplugin_continentCode,
'countryCode'=>$ip_data->geoplugin_countryCode,
'countryName'=>$ip_data->geoplugin_countryName,
);
}
return $result;
}
$visitor_details= visitor_country(); // Output Country name [Ex: United States]
$country=$visitor_details['countryName'];
WordPress 에서 post / PHP 는 기본적으로 단축 코드 페이지 내용 않으면 실행되지 않습니다.
이를 위해서는 가장 빠른 쉽고 플러그인에는 사용할 수 있는 PHP 실행하십시오 임베드됨 게시물로의 컨텐트입니다.
두 가지 다른 " 빠르고 easy"; 이 방법으로 수행할 수 없는 플러그인에는:
[2]: http://codex.wordpress.org/Page_Templates # Custom_Page_Template
이는 쉽게 솔루션이므로 단축 코드 생성. 이 같은 일이 사용하면 됩니다
function input_func( $atts ) {
extract( shortcode_atts( array(
'type' => 'text',
'name' => '',
), $atts ) );
return '<input name="' . $name . '" id="' . $name . '" value="' . (isset($_GET\['from'\]) && $_GET\['from'\] ? $_GET\['from'\] : '') . '" type="' . $type . '" />';
}
add_shortcode( 'input', 'input_func' );
Shortcode_API 참조.
이를 위해 이 플러그인을 사용할 수 있습니다 (http://wordpress.org/plugins/exec-php/) 또는 템플리트를 별도의 페이지를 만들 수 있습니다.
페이지 템플릿을 만들기 좋은 옵션입니다.
비슷한 일을 하는 것, 내가 아주 어렸을 때 됐지 따라 이러한 선:
wp-content/themes/resources/functions.php
add_action('init', 'my_php_function');
function my_php_function() {
if (stripos($_SERVER['REQUEST_URI'], 'page-with-custom-php') !== false) {
// add desired php code here
}
}