简介WordPress中用于获取首页和站点链接的PHP函数
<p><strong>home_url()(获取首页链接)</strong><br>
ome_url() 函数用来获取 WordPress 的首页链接。</p>
<p>
用法</p>
<div>
<div>
<div id="highlighter_202702">
<div>
</div>
<div>
<span>?</span>
</div>
<table border="0" cellpadding="0" cellspacing="0"><tbody><tr>
<td>
<div>
1</div>
</td>
</tr></tbody></table>
<table border="0" cellpadding="0" cellspacing="0"><tbody><tr>
<td>
<div>
</div>
</td>
<td>
<div>
<div>
<code>home_url( </code><code>$path</code><code>, </code><code>$scheme</code> <code>);</code>
</div>
</div>
</td>
</tr></tbody></table>
</div>
</div>
<div id="codetool">
<div>
<textarea></textarea>
</div>
</div>
</div>
<p>
参数</p>
<p>
$path</p>
<p>
(字符串)(可选)在首页链接后边追加的内容,是相对链接。</p>
<p>
默认值:None</p>
<p>
$scheme</p>
<p>
(字符串)(可选)链接协议,只支持 “http”,“https” 和 “relative”。</p>
<p>
默认值:null</p>
<p>
返回值</p>
<p>
(字符串)返回首页 URL 加上 $path 参数。</p>
<p>
例子</p>
<div>
<div>
<div id="highlighter_838832">
<div>
</div>
<div>
<span>?</span>
</div>
<table border="0" cellpadding="0" cellspacing="0"><tbody><tr>
<td>
<div>
1</div>
</td>
</tr></tbody></table>
<table border="0" cellpadding="0" cellspacing="0"><tbody><tr>
<td>
<div>
</div>
<div>
2</div>
<div>
3</div>
<div>
4</div>
</td>
<td>
<div>
<div>
<code>echo</code> <code>home_url();</code><code>//输出:</code><code>http://www.example.com</code>
</div>
<div>
<code>echo</code> <code>home_url( </code><code>'/'</code> <code>);</code><code>//输出:</code><code>http://www.example.com/</code>
</div>
<div>
<code>echo</code> <code>home_url( </code><code>'/'</code><code>, </code><code>'https'</code> <code>);</code><code>//输出:</code><code>https://www.example.com/</code>
</div>
<div>
<code>echo</code> <code>home_url( </code><code>'example'</code><code>, </code><code>'relative'</code> <code>);</code><code>//输出:/example</code>
</div>
</div>
</td>
</tr></tbody></table>
</div>
</div>
<div id="codetool">
<div>
<textarea></textarea>
</div>
</div>
</div>
<p>
其它<br>
此函数位于:wp-includes/link-template.php</p>
<p>
<br><strong>site_url()(获取站点链接)</strong><br>
site_url() 函数用来获取 WordPress 的站点链接。</p>
<p>
用法</p>
<div>
<div>
<div id="highlighter_186181">
<div>
</div>
<div>
<span>?</span>
</div>
<table border="0" cellpadding="0" cellspacing="0"><tbody><tr>
<td>
<div>
1</div>
</td>
</tr></tbody></table>
<table border="0" cellpadding="0" cellspacing="0"><tbody><tr>
<td>
<div>
</div>
</td>
<td>
<div>
<div>
<code>site_url( </code><code>$path</code><code>, </code><code>$scheme</code> <code>);</code>
</div>
</div>
</td>
</tr></tbody></table>
</div>
</div>
<div id="codetool">
<div>
<textarea></textarea>
</div>
</div>
</div>
<p>
参数</p>
<p>
$path</p>
<p>
(字符串)(可选)在链接后追加的内容。</p>
<p>
默认值:None</p>
<p>
$scheme</p>
<p>
(字符串)(可选)链接协议,只允许 “http”、“https”、“login”、“admin” 和 “relative”。</p>
<p>
默认值:null</p>
<p>
返回值</p>
<p>
(字符串)返回站点链接加上 $path 参数。</p>
<p>
例子</p>
<div>
<div>
<div id="highlighter_359521">
<div>
</div>
<div>
<span>?</span>
</div>
<table border="0" cellpadding="0" cellspacing="0"><tbody><tr>
<td>
<div>
1</div>
</td>
</tr></tbody></table>
<table border="0" cellpadding="0" cellspacing="0"><tbody><tr>
<td>
<div>
</div>
<div>
2</div>
</td>
<td>
<div>
<div>
<code>echo</code> <code>site_url();</code><code>//输出:</code><code>http://www.example.com 或者 http://www.example.com/wordpress</code>
</div>
<div>
<code>echo</code> <code>site_url( </code><code>'/secrets/'</code><code>, </code><code>'https'</code> <code>);</code><code>//输出:</code><code>https://www.example.com/secrets/ 或者 https://www.example.com/wordpress/secrets/</code>
</div>
</div>
</td>
</tr></tbody></table>
</div>
</div>
<div id="codetool">
<div>
<textarea></textarea>
</div>
</div>
</div>
<p>
其它</p>
<p>
此函数位于:wp-includes/link-template.php</p>
頁:
[1]