HREF =""自动添加到当前页面URL(使用PHP)。无法弄清楚 [英] HREF="" automatically adds to current page URL (in PHP). Can't figure it out

查看:104
本文介绍了HREF =""自动添加到当前页面URL(使用PHP)。无法弄清楚的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我在custom_functions.php文件中使用了Wordpress(特别是论文主题),并且因为某种原因找到了自动添加当前页面的网址。例如,这段代码是查询数据库,然后循环输出它自己的div中的每个产品:

  $ result = db_connection( $查询); 
while($ row = mysql_fetch_array($ result)){?>
< div class =box>< a href =>
< img src =http://www.electricbikehub.co.nz<?php echo $ row ['product_root_directory']。$ row ['mid_size_image']?>>
< h2><?php echo $ row ['name']?>< / h2>
< p><?php echo $ row ['description_brief'];?>< / p>
< p>< span class =multiple_product_red>< span class =multiple_product_linethrough> RRP:<?php echo $ row ['list_price']; ?>。< /跨度>我们的折扣价格:<?php echo $ row ['our_price']; ?取代。包括送货和消费税。< / span>< / p>
< / a>
< / div>
<?php}?>

正如您所看到的第3行所示,href =但生成的实际链接是当前页面(在这种情况下' http://www.electricbikehub.co.nz/?page_id=1192 ')。如果我在href中添加任何东西,比如href =something,它会将它加到最后,即 http://www.electricbikehub.co.nz/?page_id=1192something



任何帮助将不胜感激!

解决方案

这是浏览器解释和清空href的方式。它假定你想链接回你所在的页面。这与您不为< form> 元素分配操作相同。



如果添加除非你满足以下条件,否则它会将它附加到当前页面:


  • 添加一个斜杠 /

    code>到它的前面,告诉它将它附加到你的基地址 http://www.whatever.com/something

  • 添加登录,这是一个页内定位

  • 或有效的网址



编辑:有人建议我添加一个链接来帮助澄清情况。我发现以下网站我认为解释锚标签的 href 属性以及它如何解释URL路径的功能非常出色。这不是令人难以置信的技术和非常人性化的可读性。它使用大量示例来说明路径类型之间的差异: http://www.mediacollege .com / internet / html / hyperlinks.html


Longtime reader of stackoverflow but first question.

I'm working with Wordpress (specifically thesis theme) in the custom_functions.php file and am finding for some reason is automatically adding the current page url. For example this code is to query the database and then loop through outputting each product in it's own div:

$result = db_connection($query);
while ($row = mysql_fetch_array($result)) { ?>
    <div class="box"><a href="">
        <img src="http://www.electricbikehub.co.nz<?php echo $row['product_root_directory']         . $row['mid_size_image'] ?>">
        <h2><?php echo $row['name']?></h2>
        <p><?php echo $row['description_brief'];?></p>
        <p><span class="multiple_product_red"><span class="multiple_product_linethrough">RRP: <?php echo $row['list_price']; ?>.</span> Our discounted price: <?php echo $row['our_price']; ?>. Includes delivery and GST.</span></p>
        </a>
    </div>
<?php } ?>

As you can see 3rd line says href="" but the actual link being generated is the current page (in this case 'http://www.electricbikehub.co.nz/?page_id=1192'). If I add anything in the href, such as href="something" it will just add it to the end, ie http://www.electricbikehub.co.nz/?page_id=1192something.

Any help would be greatly appreciated!

解决方案

This is how a browser interprets and empty href. It assumes you want to link back to the page that you are on. This is the same as if you dont assign an action to a <form> element.

If you add any word in the href it will append it to the current page unless you:

  • Add a slash / to the front of it telling it to append it to your base url e.g. http://www.whatever.com/something
  • add a # sign in which case it is an in-page anchor
  • or a valid URL

EDIT: It was suggested that I add a link to help clarify the situation. I found the following site that I think does a really good job explaining the href attribute of anchor tags and how it interprets URL paths. It is not incredibly technical and very human-readable. It uses lots of examples to illustrate the differences between the path types: http://www.mediacollege.com/internet/html/hyperlinks.html

这篇关于HREF =&QUOT;&QUOT;自动添加到当前页面URL(使用PHP)。无法弄清楚的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆