1

我正在尝试设置一个独立的 PHP 文件,该文件能够使用当前安装的插件的简码。该文件将完全位于我当前安装的 Wordpress 之外。

我这样做是因为 ESI 需要调用 php 文件(以及最终的插件短代码功能),因为我的网站正在由 Varnish 处理。

我正在使用的插件:http ://wordpress.org/extend/plugins/custom-content-by-country/

我目前和不成功的尝试使这项工作:

<?php

// This section is experimental and not working (also the 'do_shortcode...' sections below)

include ("../../../wp-load.php");
include ("../../../wp-includes/shortcodes.php");

// end of section

$cwd = getcwd();
$path = substr($cwd, 0, strpos($cwd, 'wp-content/'));
require $path . 'wp-blog-header.php';
global $adrotate_config;

do_shortcode('[CBC country="us" show="y"]'); // not working correctly
echo adrotate_group('1'); // Working Correctly
do_shortcode('[/CBC]'); // not working correctly

do_shortcode('[CBC country="us" show="n"]'); // not working correctly
echo "Hello World!"; // Working Correctly
do_shortcode('[/CBC]'); // not working correctly

?>

任何帮助将不胜感激。谢谢

4

1 回答 1

2

您是否尝试包含在内wp-blog-header.php

您的外部文件:

define( 'WP_USE_THEMES', false );        
require('wp-blog-header.php');       

do_shortcode('[CBC country="us" show="n"]');

我刚刚尝试了以下方法,它奏效了:

外部文件:

define( 'WP_USE_THEMES', false );        
require('wp-blog-header.php');       

do_shortcode('[displayshortcode]');

函数.php 文件:

function shortcode_function() {
     echo 'shortcode';
}
add_shortcode('displayshortcode', 'shortcode_function');
于 2013-01-14T09:50:06.273 回答