2015-10-05 51 views
0

這是我第一次爲WordPress構建一個插件。我瞭解了基礎知識,但現在我正試圖在右下角顯示div,更像是僅在首頁右下角的小彈出窗口。我上傳的PHP代碼不起作用,它不斷讓我的網站崩潰。PHP WordPress插件 - 如何僅在靜態主頁上顯示div?

我的錯誤在哪裏?

請解釋你的答案。謝謝!

代碼:

<?php 
/* 
Plugin Name: My First Plugin 
Plugin URL: http://www.martinshabacom.ipage.com/test 
Description: An awesome facebook popup plugin that will amaze you! 
Author: Martin 
Version: 1.0 
Author URL: http://www.martinshabacom.ipage.com/test 
*/ 
add_action('admin_menu', 'myfirstplugin_admin_actions'); 
function myfirstplugin_admin_actions() { 
    add_options_page('MyFirstPlugin', 'MyFirstPlugin', 'manage_options', __FILE__, 'myfirstplugin_admin'); 
} 

function myfirstplugin_admin() 
{ 
?> 
<style> 
    .wrap { 
     width:100%; 
     height:auto; 
     } 

    .popup { 
     position:fixed; 
     bottom:0; 
     right:0; 
     width:325px; 
     height:200px; 
     background-color:#09f; 
    } 
</style> 


    <div class="wrap"> 

    <h1>Hello World!</h1><br> 
    <h4>Hope you like my awesome popup!</h4> 

    </div> 



<?php if(is_front_page()) { 
     <div class="popup">Testing Div Tag On The Bottom Right Corner...</div> 
    } 
?> 
<?php 
} 
?> 
+1

當你說,「[[]]不斷崩潰我的網站」,你是什麼意思?你有沒有檢查Apache錯誤日誌輸出可能涉及? – Nathan

+0

當我刪除插件文件時,我的網站又回來了! 我的意思是它顯示500錯誤的東西。 –

+0

我建議查看Apache錯誤日誌以找出原因。此外,重要的是要注意確切的錯誤代碼(不是「500錯誤的東西」)。 – Nathan

回答

1

以下部分不應該inluded的PHP if條款..

<div class="popup">Testing Div Tag On The Bottom Right Corner...</div> 

一般來說,我認爲這是更好地使用替代語法,使你的代碼更易讀:

<?php if (...) : ?> 
     your html code 
<?php endif; ?> 

編號:http://php.net/manual/en/control-structures.alternative-syntax.php

+0

我會如何將首頁回覆到首頁?我會在「你的html代碼」裏面放什麼 –

相關問題