簡體   English   中英

如何使用PHP獲取或顯示絕對鏈接的路徑?

[英]How do you get or display the path of an absolute link using PHP?

我知道這是一個簡單的問題,但我試圖從php模板中鏈接到一個php頁面。 我的模板位於:wp-content / themes / maton-theme / main.php

我鏈接到的文件位於同一個目錄中我嘗試了一些東西,但我的代碼是錯誤的。

<a href="<?php $url = includes_url('post-2.php'); ?>">Link</a>

我也嘗試使用簡單的鏈接:

<a href="post-2.php">Link</a>

但是因為我使用的是主題,所以它沒有用,鏈接轉到http://local.test.com/main/post-2.php ,我得到一個Page not found錯誤。

如何鏈接到同一目錄中的另一個php文件? 另外,有沒有辦法顯示整個URL路徑?

我不建議你做你正在做的事情。 最好在WordPress中創建一個帶有自定義模板的帖子並鏈接到該帖子。 但是我可能會錯過你需要這樣做的原因。 所以你需要做的是使用get_template_directory_uri()獲取模板目錄URL。

<a href="<?php echo get_template_directory_uri(); ?>/post-2.php">Link</a>

參考: https//developer.wordpress.org/reference/functions/get_template_directory_uri/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM