将我的标记链接到其他网站搜索

时间:2012-12-11 10:36:22

标签: php search hyperlink tags

这是我的搜索代码

<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上,这样用户就不必输入?我想在其他网站搜索中搜索我的标签

2 个答案:

答案 0 :(得分:0)

一个简单的方法是从您输入搜索查询的文本框中获取值,并使用onsubmit()创建一个javascript函数 var searchkeyword=document.forms["formname"]["textboxname/id"].value; window.location("www.othersite.com/"+searchkeyword);

答案 1 :(得分:0)

经过一夜的尝试&amp;错误,我想我已经找到了,这里是代码的细节:

<?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打开指向新标签的链接?

相关问题