2013-10-07 42 views
-3

我想在wordpress中使用下面的代碼。我怎樣才能做到這一點?在wordpress頁面中允許php

<?php 
$theme_name = get_template(); 
$directory = "wp-content/themes/" . $theme_name . "/pdf/ECE340/"; 
$pdfs= glob($directory . "*.pdf"); 
foreach($pdfs as $pdf) 
{ 
$link= substr($pdf,48,90); 
?> 
<a href="<?php echo $pdf; ?> "><?php echo $link; ?></a> 
<?php 
echo "\n\n"; 
echo "<br />"; 
} 
?> 
+1

創建簡碼或在wordpress模板中添加代碼 –

回答

0

下面是答案(從here拍攝):

add_filter('widget_text','execute_php',100); 
function execute_php($html){ 
    if(strpos($html,"<"."?php")!==false){ 
      ob_start(); 
      eval("?".">".$html); 
      $html=ob_get_contents(); 
      ob_end_clean(); 
    } 
    return $html; 
} 

複製在你的functions.php文件的末尾上述功能。

最佳解決方案將創建一個自定義模板,而不是在頁面/窗口小部件/帖子中使用PHP。你會發現更多關於WordPress的自定義模板here

0

登錄到您的管理面板。點擊左側菜單中的Appearance -> Editor。然後在右側菜單中找到想要添加PHP代碼的地方Template。然後你可以在編輯器中添加你的PHP代碼。

注意:確保在做任何編輯之前進行備份。我對你的錯誤不負責任。