2010-11-17 42 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。

相關問題