我已經完成了所有的 html 頁面,現在我想將它們添加到 header.php 中。
請看下面的代碼:
<li class="menu-item"> <a href="<?php the_permalink('/aboutus.html'); ?>"> AboutUs</a> </li>
正如您所看到的,我使用 the_permalink 函式來呼叫 html 檔案,但是當我在導航欄中單擊時,什么都沒有發生,我沒有得到 aboutus.html。
你能告訴我如何理解我的觀點嗎?
uj5u.com熱心網友回復:
您不會從 PHP 輸出任何內容。更改<?php
為<?=
:
<li class="menu-item"> <a href="<?= the_permalink('/aboutus.html'); ?>"> AboutUs</a> </li>
uj5u.com熱心網友回復:
檢查該命令的手冊: https ://developer.wordpress.org/reference/functions/the_permalink/
如果您在沒有任何引數的情況下呼叫該函式,它將輸出當前頁面的 url。如果要指定其他頁面,則必須傳遞該頁面 id 或 WP_Post 物件型別。我會說,您試圖傳遞一些包含頁面 url 的字串,這是不受支持的。
uj5u.com熱心網友回復:
<li class="menu-item"> <a href="<?php echo $location_of_file .'/aboutus.html'; ?>"> AboutUs</a> </li>
$location_of_file 將包含 aboutus.html 檔案的地址,末尾沒有斜線。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/494788.html
上一篇:Python:使用BeautifulSoup提取HTML<main>資料
下一篇:返回列表