首页 文章

WordPress页面模板中的PHP代码不执行[关闭]

提问于
浏览
0

任何人都可以告诉我为什么wordpress'页面模板'中的代码不执行?

'Echo'似乎有效,但所有'include'和'print_r()'以及其他功能都没有 . 这个确切的代码适用于我的家庭服务器,但不适用于wordpress托管网站:

<?php

/**
 * Template Name: fbshares
 *
 * A custom page template for displaying all posts.
 *
 * The "Template Name:" bit above allows this to be selectable
 * from a dropdown menu on the edit page screen.
 *
 * @package WordPress
 * @subpackage Twenty_Ten
 * @since Twenty Ten 1.0
 */

get_header(); ?>

<div id="container">
<div id="content" role="main" class="fullpagejoel">

 <?php 
    echo "x";
    $url = "http://www.google.com";

    $social = array(
        'twitter' => 'http://cdn.api.twitter.com/1/urls/count.json?url=',
        'facebook' => 'https://graph.facebook.com/',
        'stumbleupon' => 'http://www.stumbleupon.com/services/1.01/badge.getinfo?url='
    );

    $json = file_get_contents($social['twitter'].$url, false);
    $a = json_decode($json, true);
    $r['twitter'] = $a['count'];

    print_r($a);
    echo count($a).' [OK]';

 ?>

2 回答

  • 0

    没有足够的代表评论,但你检查了来源? WordPress会默默地死去,但通常会在源代码中出现问题 .

    简而言之,是的,你可以在模板中执行你想要的任何php . 我只是将它粘贴到我们的测试服务器上的WordPress模板中,它运行正常 .

  • 0

    我刚发现了这个问题 . 逐项调试每个位后,问题是WordPress不允许你运行 file_get_contents ,而是你必须像这样使用 wp_remote_get

    GOOD: $json = wp_remote_get( $social['twitter'].$url );
    BAD: $json = file_get_contents($social['twitter'].$url, false);
    

    我只是浪费了整整一天的时间,所以我希望它可以帮助别人 .

相关问题