我在以下代码中获得了大部分内容,并得到了http://www.php.net 和http://codex.wordpress.org/Function_Reference/.
在当前情况下,如果没有设置cookie,则站点上只有一个页面会触发弹出窗体。此代码中是否指定了该功能?
功能如下:
if (isset($_POST[\'confirm\']) && isset($_POST[\'location\'])) {
setcookie("Location", $_POST[\'location\'], time()+3600);
}
elseif (!isset($_COOKIE["Location"])) {
setcookie("Location", "", 1);
}
elseif (isset($_POST[\'deny\'])) {
setcookie("Location", "", 1);
}
// Popup confirmation
function show_popup($content) {
global $post;
$location = get_post_meta($post->ID, \'location\', TRUE);
if (strtolower($l) == strtolower($location) || strlen($location) == 0
|| (isset($_COOKIE["Location"]) && strtolower($_COOKIE["Location"])
== strtolower($location))) {
return $content;
} else {
?>
<div id="popup">
<p>Foo.</p>
<p>Yes/No?</p>
<form action="<?php echo $PHP_SELF ?>" method="post">
<input type="hidden" name="location" value="<?php echo $location; ?>" />
<input type="submit" name="confirm" value="Yes" />
<input type="submit" name="deny" value="No" />
</form>
</div>
<?php
}
}
add_filter(\'the_content\', \'show_popup\');
// Adds content to the <head> tag
function add_meta_content() {
if(isset($_POST[\'deny\'])) {
?>
<meta http-equiv="refresh" content="0;url=<?php bloginfo (\'wpurl\') ?>">
<?php
}
if(isset($_POST[\'confirm\'])) {
?>
<meta http-equiv="refresh" content="0;url=<?php echo $PHP_SELF; ?>">
<?php
}
}
add_action(\'wp_head\', \'add_meta_content\');
最合适的回答,由SO网友:Bainternet 整理而成
确保post作为名为\'location\'
您正在查看的页面正在使用the_content()
或者,如果您希望此操作适用于类别和归档,请添加:
add_filter(\'the_excerpt\', \'show_popup\');
希望这有帮助