2014-02-06 62 views
0

我在我的wordpress頁面上做了一個動態選擇框來選擇類別和子類別。從網址中刪除特定的字符串

輸出url應該是http://myurl.com/category/maincategory/subcategory 但表格給出http://myurl.com/category/maincategory/?xy=maincategory+subcategory

我認爲最簡單的解決方案是,如果一個jQuery腳本將刪除「?」之間的特定部分和「+」來自實時網址,但我不知道如何。

這將是一個旅館發現者,這裏是完整的代碼。一些腳本用於動態選擇框的寬度。

<form method="get" action="<?php bloginfo('url'); ?>"> 
<fieldset> 
I'd like to find a nice hostel in 
<select name="category_name" id="orszag" style="width: auto;"> 
<option value="hostels">any country</option> 
<?php 
// generate list of categories 
$categories = get_categories('hide_empty=1&style=none&parent=2'); 
foreach ($categories as $category) { 
    echo '<option value="', $category->slug, '">', $category->name, "</option>\n"; 
} 
?> 
</select> 
, 


<select class="calc_dropdown calclinkone" id="varos" name="varos" style="width: auto;"> 

<option value="hostels ">any city</option> 


<option value="hungary ">any city</option>   
     <?php 
// generate list of categories 
$categories = get_categories('child_of=3&hide_empty=0'); 
foreach ($categories as $category) { 
    echo '<option value="hungary ', $category->slug, '">', $category->name, "</option>\n"; 
} 
?> 





<option value="uk ">any city</option>   
     <?php 
// generate list of categories 
$categories = get_categories('child_of=6&hide_empty=0'); 
foreach ($categories as $category) { 
    echo '<option value="uk ', $category->slug, '">', $category->name, "</option>\n"; 
} 
?> 






<option value="slovakia ">any city</option>   
     <?php 
// generate list of categories 
$categories = get_categories('child_of=17&hide_empty=0'); 
foreach ($categories as $category) { 
    echo '<option value="slovakia ', $category->slug, '">', $category->name, "</option>\n"; 
} 
?> 




<option value="germany ">any city</option>   
     <?php 
// generate list of categories 
$categories = get_categories('child_of=4&hide_empty=0'); 
foreach ($categories as $category) { 
    echo '<option value="germany ', $category->slug, '">', $category->name, "</option>\n"; 
} 
?> 

</select> 





<br> 
for 
<select> 
<option value="">1</option> 
<option value="">2</option> 
<option value="">3</option> 
<option value="">4</option> 
<option value="">5</option> 
<option value="">6</option> 
</select> 
person for 
<select> 
<option value="">1</option> 
<option value="">2</option> 
<option value="">3</option> 
<option value="">4</option> 
<option value="">5</option> 
<option value="">6</option> 
</select> nights.<br> 
<button type="submit"><i class="fa fa-search"></i> Search</button> 
</fieldset> 
</form> 


<script> 

$("#orszag").change(function() { 
if($(this).data('options') == undefined){ 
    $(this).data('options',$('#varos option').clone()); 
    } 
var id = $(this).val(); 
var options = $(this).data('options').filter('[value*=' + id + ']'); 
$('#varos').html(options); 
}); 


$('select').change(function() { 
    var $opt = $(this).find("option:selected"); 
    var $span = $('<span>').addClass('tester').text($opt.text()); 

    $span.css({ 
     'font-family': $opt.css('font-family'), 
     'font-style': $opt.css('font-style'), 
     'font-weight': $opt.css('font-weight'), 
     'font-size': $opt.css('font-size') 
    }); 

    $('body').append($span); 
    // The 30px is for select open icon - it may vary a little per-browser 
    $(this).width($span.width() + 10); 
    $span.remove(); 
}); 

$('select').change(); 

</script> 

謝謝!

+0

你能粘貼一些代碼嗎? – cschuff

+0

你確定wordpress不會因爲某種原因而添加這些內容嗎?如果不是,則解析該字符串並移除搜索部分。 – adeneo

回答

0

使用jQuery的替代方法

var mystring = "hellothis"; 
    var m = mystring.replace("this", "that"); 
    alert(m); 

會產生 「hellothat」

var myUrl = "http://myurl.com/category/maincategory/?xy=maincategory+subcategory" 
var newURL = myUrl.replace("?xy=maincategory+",""); 

應該給你想要的

0

什麼我在這裏現在。 我有這個

$(document).ready(function() { 
    if(window.location.href.indexOf("?") > -1) { 
     location.href=location.href.replace("?varos=germany+", ""); 
    } 
}); 

的代碼工作好,如果我是德國。現在我必須將?varos=germany+部分更改爲定義字符串之間動態部分的內容?和+並將其刪除。

相關問題