2012-12-11 37 views
-3

這是我的搜索代碼鏈接我的標籤上的其他網站的搜索

<div id="search"> 
    <form method="get" action="http://www.other-website.com/search"> 
     <input type="hidden" name="f" value=""> 
     <input type="text" placeholder="Temukan informasi, komunitas & produk yang kamu cari disini" accesskey="s" name="q"> 
     <input type="submit" value="Search"> 
    </form> 
</div> 

這是標記代碼(僅顯示文本「不鏈接」)

<?php 
$posttags = get_the_tags(); 
if ($posttags) { 
    foreach($posttags as $tag) { 
    echo $tag->name . ' '; 
    } 
} 
?> 

的代碼可以很好的適用該網站,但我必須輸入文字進行搜索。我只想把我的標籤放在搜索文字上

所以我的問題是 如何讓固定詞(我的標籤)自動放在搜索上或我必須放置標籤碼的地方,搜索結果是mytag鏈接在@ www.other-website.com/search因此用戶不必輸入?我想搜索其他網站上搜索我的標籤

+0

我不明白你在說什麼。 – transilvlad

回答

0

經過一夜嘗試& errorr,我想我已經找到了,這裏是代碼的細節:

<?php 
$posttags = get_the_tags(); 
if ($posttags) { 
    foreach($posttags as $tag) { 
     $tag_link = 'http://xxx.orhersite.xxx'; 
     echo "<a href='$tag_link/$tag->name'>"; 
     echo "$tag->name"; 
    } 
} ?> 

,可以直接到其他網站的搜索xxx.othersite.xxx/search/my-tag 但現在其他問題表明,如果用戶點擊該鏈接,它會在同一頁面打開。 我試過

echo "<a href onclick="window.open(''); 

<?php 
$posttags = get_the_tags(); 
if ($posttags) { 
    foreach($posttags as $tag) { 
     $tag_link = 'http://xxx.orhersite.xxx'; 
     echo "<a href onclick="window.open('$tag_link/$tag->name')">"; 
     echo "$tag->name"; 
    } 
} ?> 

如何打開鏈接到該代碼使用的onClick新標籤?

0

一個簡單的方法走的是價值,從那裏你輸入搜索查詢和使用onsubmit()文本框創建一個JavaScript函數 var searchkeyword=document.forms["formname"]["textboxname/id"].value; window.location("www.othersite.com/"+searchkeyword);

+0

@ ganeshrj謝謝,你如何在我的應用程序,對不起,因爲我沒有編碼經驗。 :) –

+0

請給我你的代碼你做了什麼。所以我可以提供建議。 –

+0

<?php $ posttags = get_the_tags(); if($ posttags){ foreach($ posttags as $ tag){ $ tag_link ='http://xxx.orhersite.xxx'; echo「」; echo「$ tag-> name」; } }?> –

相關問題