我寫這段代碼的PDF文件的PHP名單:WordPress的 -
function userfunc_get_file_links($sub_folder) {
if (is_user_logged_in()) {
$directory = get_stylesheet_directory()."/files/".$sub_folder;
$scanned_directory = array_diff(scandir($directory), array('..', '.'));
echo "<ul class='support_links'>";
foreach ($scanned_directory as $key => $value) {
echo "<li><a href='files/".$value."'>".$value."</a></li>";
}
echo "</ul>";
}
}
我已經把它添加到我的功能文件,我可以成功地與一個頁面模板應用它,它顯示的列表文件鏈接。
(模板文件):
<?php
/*
Template Name: supportpage
*/
?>
<?php get_header(); the_post(); ?>
<div id="content" class="inner-page">
<div class="main-content">
<div class="brack-cum">
<div class="inner-small">
<?php
if (function_exists('wp_bac_breadcrumb')) {wp_bac_breadcrumb();}
?>
</div>
</div>
<div class="title">
<div class="inner-small">
<h2><?php the_title(); ?></h2>
</div>
</div>
<div class="content-page inner-small">
<?php
the_content();
?>
</div>
</div>
<?php get_footer(); }?>
然而,當我點擊他們它帶來了一個404錯誤,我不明白爲什麼。我試過重置我的固定鏈接並檢查FTP路徑(它的100%正確)。
如果我盡我的/文件/文件夾移動到服務器的根目錄中
$directory = home_url()."/htdocs/files".$sub_folder;
它返回
警告:SCANDIR(01): 未能打開目錄:不實施於 C:\ xampp \ apps \ wordpress \ htdocs \ wp-content \ themes \ twentythirteen-child \ user_functions.php on line 5
這些文件大部分是pdf文件(「how_to_do_stuff.pdf」等)。
關於我可以從這裏採取的步驟的任何想法?
EDIT1:隨着原代碼顯示的鏈接,但在點擊返回的WordPress 404:
的var_dump($目錄)
string(93) "C:\xampp\apps\wordpress\htdocs/wp-content/themes/twentythirteen-child/files/application_notes"
的var_dump($ scanned_directory)
array(3) {
[2]=>
string(9) "test1.pdf"
[3]=>
string(9) "test2.pdf"
[4]=>
string(9) "test3.pdf"
}
隨着生成警告的代碼:
var_dump($ directory)
string(57) "http://localhost/wordpress/htdocs/files/application_notes"
的var_dump($ scanned_directory)
NULL
轉儲$目錄和$ sc anned_directory,你會得到什麼? – Mihai
@Mihai編輯顯示 – Ridai
該目錄看起來很奇怪我使用\的窗口比開關/用於linux – Mihai