2010-11-17 39 views
2

如何在WordPress的所有网页上的所有网址中添加一些参数?我正在进行主题开发,我需要向潜在客户展示使用它的不同变体。所以,我有不同的配色方案。我找到了一个关于如何从url获取参数的教程,并在我的代码中使用它们。现在,我可以轻松使用像http://proceed.skible.com/?color=magic_night这样的网址将颜色方案设置附加到CSS文件。它工作正常,但是当我点击演示页面上的任何链接时,它显然不会应用我的自定义颜色方案,而是应用保存在设置中的颜色方案。我想我可以这样 - 添加?color = magic_night或任何我需要的颜色方案给所有链接。当然,我需要解析链接并以正确的方式添加链接,而不是将其插入每个网址的末尾。除此之外,可能有更好的方法来实现预览主题的其他功能的可能性吗?我看到了我在这里描述的方式:http://themes.mysitemyway.com/infocus/?themedemo=infocus&extracss=deep_blue。所有链接都以extracss = deep_blue结尾,或者从菜单中选择另一个主题。 谢谢。将一些参数添加到WordPress的所有网址中

回答

1

您应该使用PHP Cookie存储HTTP请求的用户色彩偏好,但允许他们使用你所谈论的GET变量来覆盖它:

# Get the value of color if specified on the URL (GET) or in a cookie 
# If non of those place have the color, then color will be NULL 
$color = isset($_GET['color']) ? $_GET['color'] : (
    isset($_COOKIE['color']) ? $_COOKIE['color'] : NULL 
); 

# If we know what color we have and didn't just get it from a cookie 
# then set a cookie with that color as its value 
if ($color != NULL && isset(! $_GET['cookie'])) { 
    setcookie('color', $color); 
} 

现在,你有$color值即可选择你想要的样式表,例如:

<?php 
    if ($color != NULL) { 
     ?> <link rel="stylesheet" href="<?php bloginfo('stylesheet_direcctory'); ?>/<?php print($color); ?>.css" type="text/css" /> <?php 
    } 
?> 

PS我的PHP语法有点生疏,但概念应该是全部有

0

如果我正确地理解你,你想使用一个不同的样式表基于什么url参数传递?你可以做,在你的主题的头文件:

的header.php:

//includes 
<html> 
... 
<head> 
... 
<? 
if($_GET['color'] == 'magic_night'){ 
?> 
<link rel="stylesheet" href="<?php bloginfo('stylesheet_direcctory'); ?>/magic_night.css" type="text/css" /> 
<? 
} 
else 
... 
?> 
...rest of the page... 

代码bloginfo(“stylesheet_direcctory”)应该让你到你的主题目录,但我会在测试第一回声它文件或使用更好的参数bloginfo。

相关问题