2016-07-24 24 views
0

真的希望有人能幫助我。我需要達到以下要求: 在頁面頂部更改語言時,品牌div(帶有紙飛機的條)會更改順序以顯示首先使用該語言的網站。這將在wordpress網站上,並利用翻譯插件。我有點不確定從哪裏開始,我對Onclick事件瞭解甚少,但我的知識卻非常有限。任何幫助將非常感激。當前的開發網站可以在這裏找到:http://atsreisen.eighty3.co.uk/de/如何根據選擇的語言來定購品牌分區?

+0

沒有足夠的信息給出正確的答案。例如,一些WP翻譯插件通過創建可編輯的重複頁面來操作,因此重新安排「div」可能與編輯適當的翻譯一樣簡單。 –

+0

感謝您的回覆。它看起來就是這個插件的情況。唯一的問題是,我似乎無法看到德國網頁的生成地點。當我查看後端時,它沒有任何內容,只是拉英文版 – mischiefbec

+0

我操作過的大多數翻譯插件通常都在主頁上有一個切換,以向您展示各種翻譯選項。查找右側的下拉菜單或某些檢查翻譯的元素。 –

回答

0

如果我完全理解,您需要將頂部的語言附加到品牌div。你可以通過在你的鏈接中添加html和id的data-lang屬性來實現。 (data-something)是您創建用於jQuery的自定義屬性的一種方式。

<a class="lang" href="#0" id="german">German</a> 
<a class="lang" href="#0" id="english">English</a> 
<div id="container"> 
    <div data-lang="german">This is a brand div</div> 
    <div data-lang="english">This is another brand div</div> 
    <div data-lang="english">This is an English brand div</div> 
</div> 

然後在jQuery的你可以這樣做:

//variables (caching) 
var langLink = $('.lang'); 
var langId; 
var dataLang; 

langLink.on('click', function(event) { 
    // this part to prevent the page from refreshing when the link is clicked 
    event.preventDefault(); 
    // get the clicked links Ids, hence $(this) 
    langId = $(this).attr('id'); 
    // go up to a parent the links and divs share here it's the body 
    // then finding the divs that has data-lang matching the links id 
    dataLang = $(this).parent('body').find('div[data-lang="' + langId + '"]'); 
    // a temporary storage to store all the divs that match the language clicked 
    var temp = []; 
    // pushing the found divs to the temp storage 
    temp.push(dataLang); 
    // removing them from the dom 
    dataLang.remove(); 
    // and finally looping through the temp storage array and prepending it to the container 
    for (var i = 0; i < temp.length; i++) { 
    $('#container').prepend(temp[i]); 
    } 
}); 

這是我會怎樣,但我敢肯定還有其他的方法來做到這一點。 如果你想看到它在行動嘗試這JSFiddle

0

如果你使用wordpress,你可以通過很多方式實現這一點。最簡單的方法是修改wordpress主題頭(理想的是通過一個兒童主題),並添加一個「if條件」來檢測當前的wordpress語言並相應添加一個類到主體中;你可以通過使用wordpress get_locale()函數來完成。然後,您可能需要一個小小的javascript,或者理想的jQuery來獲取品牌div並對它們重新排序。