2012-11-07 123 views
1

我對wordpress非常陌生,越來越困惑,以至於如何爲wordpress自定義模板創建自定義url重寫。我也嘗試在谷歌上找到它,但沒有運氣。我無法找到適當的解決方案。自定義模板的wordpress url重寫

這裏是我當前的URL結構:使用自定義URL重寫我

http://example.com/chiptuning/search/?brand=Audi 

想將其轉換爲

http://example.com/chiptuning/search/brand/audi 

,或者它可能是

http://example.com/chiptuning/search/Audi 

請還別說在那裏放置代碼。

UPDATE

由@Mike劉易斯提供的答案已經由我,但它並沒有提供什麼,我找的,反正感謝@Mike劉易斯答覆。

其他人對這個問題有什麼建議嗎?我需要快點,請。

Thanx提前。

回答

3

WordPress會自行尋找使用哪個模板文件。如果你知道重寫規則,你可以看看通過這些頁面:

OR,這裏有幾個簡單的解決方案:

使用分層頁面

site.com/page1/sub-page/sub-page/

您必須使用瀏覽器通過/ wp-admin /添加頁面,然後在其中設置其父頁面。您也可以選擇使用特定模板(PHP主題文件)(請參閱:Theme Development並向下滾動到自定義頁面模板)。

採用分層分類

你也可以使用分層分類標籤的帖子,然後列出它們的類別檔案網頁。例如:

您可以擁有site.com/category/brand/audi/(注意,您可以在wordpress設置中更改此網址的「類別」基本部分)。

您可以爲各種標籤歸檔頁面創建模板文件:category-brand.php將爲site.com/category/brand/ url加載,而category-audi.php將加載爲site.com/category/brand/audi/ url。

注意:根據您的網站的動態需求,您可能需要跳過使用category- {tag} .php,以便它通過泛型category.php。在這種情況下,我相信上述兩個網址都會使用通用類別。php(缺少更具體的模板文件 - Template Hierarchy向下滾動以查看模板層次結構圖)。

這會阻止您必須爲每個單獨的標記創建單獨的文件。使用get_query_var()方法獲取特定類別標籤。

最後但並非最不重要

如果仍然遭到拒絕,有另一種方式來切割的URL,而無需使用重寫規則。 BuddyPress(一個WordPress插件)有一個功能,可以將url分成幾塊(/ 1/2/3 /),然後在PHP中使用它們。我不確定這是如何工作的,但如果你想看一下,你可以谷歌/下載BuddyPress,並查看buddypress/bp-core/bp-core-catchuri.php文件。

這裏的文檔塊:

/** 
* Analyzes the URI structure and breaks it down into parts for use in code. 
* BuddyPress can use complete custom friendly URI's without the user having to 
* add new re-write rules. Custom components are able to use their own custom 
* URI structures with very little work. 
* 
* @package BuddyPress Core 
* @since BuddyPress (1.0) 
* 
* The URI's are broken down as follows: 
* - http:// domain.com/members/andy/[current_component]/[current_action]/[action_variables]/[action_variables]/... 
* - OUTSIDE ROOT: http:// domain.com/sites/buddypress/members/andy/[current_component]/[current_action]/[action_variables]/[action_variables]/... 
* 
* Example: 
* - http://domain.com/members/andy/profile/edit/group/5/ 
* - $bp->current_component: string 'xprofile' 
* - $bp->current_action: string 'edit' 
* - $bp->action_variables: array ['group', 5] 
* 
*/ 
function bp_core_set_uri_globals() { 
+0

這個插件已經由我和它沒有運氣:(你有任何其他的想法或其他建議,請我需要它快:)? –