Html 在 wordpress 中链接回主页
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12889093/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Linking back to home page in wordpress
提问by Sidetracking
So I have WordPress installed in a subdirectory of my website with permalinks set up.
所以我在我网站的子目录中安装了 WordPress,并设置了永久链接。
I have my website set up like so:
我的网站设置如下:
-index.php
-style.css
-/contact
---index.php
-/blog
---(Wordpress installation)
So my problem is, whenever I use an <a href="../">Home</a>
to link back to my homepage, it only works from my main blog page. If I go to a permalink post it takes me back to the blog home.
所以我的问题是,每当我使用 an <a href="../">Home</a>
链接回我的主页时,它只能在我的主博客页面上工作。如果我转到永久链接帖子,它会将我带回博客主页。
What I'm wondering is, is there a way to link back to the main page on both my blog home, and a permalink post? If i use ../../ it works on the post, but not the blog home.
我想知道的是,有没有办法链接回我的博客主页和永久链接帖子的主页?如果我使用 ../../ 它适用于帖子,但不适用于博客主页。
I hope I worded this clearly enough, if I missed anything please let me know. Any help greatly appreciated, thanks.
我希望我的措辞足够清楚,如果我错过了什么,请告诉我。非常感谢任何帮助,谢谢。
回答by coderabbi
<a href="<?php echo home_url(); ?>">Home</a>
回答by oal
You can use the home_url
function: http://codex.wordpress.org/Function_Reference/home_url
您可以使用该home_url
功能:http: //codex.wordpress.org/Function_Reference/home_url
I also recommend checking out the WordPress Function reference, and use the appropriate built in functions rather than inventing your own.
我还建议查看 WordPress 函数参考,并使用适当的内置函数,而不是自己发明。
Edit: Not sure if you want to go back to the main index, or the WordPress index. If you just want to link back to your first index.php
, you can simply use <a href="/>Home</a>
编辑:不确定您是要返回主索引还是 WordPress 索引。如果您只想链接回您的第一个index.php
,您可以简单地使用<a href="/>Home</a>