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!
Answer: Use the window. location. href Property location. href property to get the entire URL of the current page which includes host name, query string, fragment identifier, etc.
Definition and Usage The href attribute specifies the URL of the page the link goes to. If the href attribute is not present, the <a> tag will not be a hyperlink. Tip: You can use href="#top" or href="#" to link to the top of the current page!
Of course it can. The PHP part is just the language that the server is instructed to interpet the page in. Then it sends regular HTML back to the client browser, who uses the anchors to jump around the HTML document. IDs are the correct way to do it, on any visible element.
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:
/
to the front of it telling it to append it to your base url e.g. http://www.whatever.com/something
#
sign in which case it is an in-page anchorEDIT: 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
Add http:// in front of url
Incorrect
<a href="www.example.com">www.example.com</span></p>
Correct
<a href="http://www.example.com">www.example.com</span></p>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With